java JUnit自定义运行程序不工作?
我正在尝试编写一个定制的Runner,它只是按照随机顺序进行测试。跑步者:
public class TestClassRunnerForParameters extends BlockJUnit4ClassRunner {
public TestClassRunnerForParameters(Class<?> type) throws Exception {
super(type);
}
protected java.util.List<org.junit.runners.model.FrameworkMethod> computeTestMethods() {
java.util.List<org.junit.runners.model.FrameworkMethod> methods = super
.computeTestMethods();
Collections.shuffle(methods);
return methods;
}
}
现在,如果不是参数化测试,它可以正常工作。是否可以使用参数测试来实现这一点?实现参数化接口
# 1 楼答案
只需添加一个构造函数(按照建议):
并将其委托给构造函数。在这种情况下,构造函数应该是
public
,因为JUnit/Surefire正在使用反射# 2 楼答案
我得说,这个错误是相当自我描述的:
您的类没有具有该签名的构造函数。它唯一的构造函数有参数
Class<?> type
、List<Object[]> parameterList
和int i
。你应该去掉后两个论点。另外,这个构造器不是public
;你应该在它前面加public
此外,如果您试图构建参数化测试,可能会在
org.junit.runners.Parameterized
运行程序中进行测试,因为它正是这样做的。这是一个好主意