【问题标题】:Maven Surefire Junit test suiteMaven Surefire Junit 测试套件
【发布时间】:2016-01-26 08:03:40
【问题描述】:

我正在使用 Maven Surefire 插件来运行特定的测试套件。 例如:

package suite;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import suite.slow.EvenSlowerClassTest;
import suite.slow.SlowClassTest;

@RunWith(Suite.class)
@Suite.SuiteClasses({
    SlowClassTest.class,
    EvenSlowerClassTest.class
})
public class SlowSuite {

}

通过使用maven命令

test -DrunSuite=**/FastSuite.class -DfailIfNoTests=false

我可以显式运行 FastSuite 或 SlowSuite 测试套件,但是,如何运行我拥有的所有测试套件或测试套件未涵盖的所有测试?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <includes>
            <include>${runSuite}</include>
        </includes>
    </configuration>
</plugin>

【问题讨论】:

  • mvn test 将在src/test/java 下运行所有​​测试(顺便说一句,我没有投反对票)
  • 是的,我知道。但是如果我在surefire插件中有include指令(我用pom.xml更新了问题)它默认运行一个套件。如果我不添加该包含,我将无法运行任何提供参数的套件
  • 你试过-DrunSuite=**/* 吗?
  • @CédricCouralet 属性 runSuite 在 maven-surefire-plugin 中不存在,请参阅文档。
  • 这是一个包含的属性。 @CédricCouralet 有帮助,谢谢。

标签: java maven junit surefire


【解决方案1】:

我在我们的一些项目中所做的是在pom.xml 中使用&lt;profiles&gt; 来激活特殊的测试套件。如果没有配置文件处于活动状态,所有测试都将使用mvn test 运行(我希望这就是您要寻找的)

像这样:

<profile>
    <id>commit-test</id>
    <build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.3</version>
            <configuration>
                <groups>com.test.CommitTest</groups>
            </configuration>
        </plugin>
    </plugins>
</build>

测试类的注释如下:

@Category(CommitTest.class)
public class SomeTestClass {
}

我不知道它是否适用于 @Suite@RunWith 但如果你的测试套件不是太多的类,那么改变它应该不是一件难事。

命令:mvn clean test -Pcommit-test

【讨论】:

  • Category注解从何而来?我在 junit 框架中找不到它
  • junit-4.11org.junit.experimental.categories
【解决方案2】:

我想你可以试试 -DrunSuite=**/*Suite.class

【讨论】:

猜你喜欢
  • 2018-09-02
  • 2020-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-26
  • 1970-01-01
  • 2020-07-25
  • 2022-01-14
相关资源
最近更新 更多