java – 如何使用参数化构造函数运行junit

我必须从命令行运行junit测试,团队中的一个人创建了如下所示的junit类:

public Test extends TestCore
{
   String some;

   public Test(String some)
   {
      this.some = some;
   }
//some test here
}

这项工作来自日食,但不是来自命令行.
执行这种文件的结果给了我如下错误:

Test class should have exactly one public zero-argument constructor.

有人可以帮帮我吗?

干杯雅罗斯瓦夫.

最佳答案 Eclipse使用不同的testrunner.也许参数化构造函数是由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?

点赞