【问题标题】:Maven not finding tests from a test suite classMaven 没有从测试套件类中找到测试
【发布时间】:2017-09-18 18:43:28
【问题描述】:

我正在使用 maven 运行一系列 JUnit 测试,我已经更改了代码,因此我使用了这样的测试套件类,而不是使用 @Test 注释:

public class MyTests {
  public static Test suite() {
    TestSuite ts = new TestSuite("My Test Suite");
    ts.addTest(new CustomTestCase1("Test 1"));
    ts.addTest(new CustomTestCase2("Test 2"));
    ...
    return ts;
  }
}

当我运行一个

mvn clean -U -fn -Dtest=MyTests test

我得到一个没有执行任何测试!

谁能指出我如何使用 maven 运行测试,而不是为每个类创建一个测试运行器?

【问题讨论】:

  • 你好,为什么不使用'@Test'和'@Suite'注解?因为我认为 Junit 4/5 是不可能的,而只有 JUnit 3 是不可能的。
  • @fandango 因为我希望能够将“CustomTestCase1”作为可重用的测试用例。

标签: java maven unit-testing testing junit


【解决方案1】:

您应该能够使用-DrunSuite 标志运行套件:

mvn clean -U -fn -DrunSuite=MyTests test 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 2017-05-21
    • 2012-02-17
    • 1970-01-01
    相关资源
    最近更新 更多