我必须从命令行运行 junit 测试,团队中的一个人创建了如下所示的 junit 类:
public Test extends TestCore
{
String some;
public Test(String some)
{
this.some = some;
}
//some test here
}
这在 eclipse 中有效,但在命令行中无效。 执行这种文件的结果给我如下错误:
Test class should have exactly one public zero-argument constructor.
谁能帮帮我?
干杯雅罗斯瓦夫。
最佳答案
Eclipse 使用不同的测试运行器。也许参数化构造函数是由 TestCore
作为参数化测试引起的,例如像这样:
@RunWith(Parameterized.class)
public class TestCore {
String someThatWillBeHidden;
public TestCore(String some) {
this.someThatWillBeHidden = some;
}
@Parameters
public static List<Object[]> data() {
Object[][] data = new Object[][] { {"Hello"}, {" "}, {"world"}};
return Arrays.asList(data);
}
//some test here
}
那么您使用的是哪个版本的 junit?
关于java - 如何使用参数化构造函数运行 junit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7334876/