Maven Surefire Junit测试套件 [英] Maven Surefire Junit test suite
问题描述
我正在使用Maven Surefire插件来仅运行特定的测试套件. 例如:
I am using the Maven Surefire plugin in order to run just a specific suite of tests. For instance:
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命令
By using the maven command
test -DrunSuite=**/FastSuite.class -DfailIfNoTests=false
我可以显式运行FastSuite或SlowSuite测试套件,但是,如何运行我拥有的所有测试套件或测试套件中未涵盖的所有测试?
I can run the FastSuite or SlowSuite test suites explicitly, however, how can I run all test suites that I have or all tests that are not covered in a test suite?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
</configuration>
</plugin>
推荐答案
我在某些项目中所做的工作是使用pom.xml
中的<profiles>
激活特殊的测试套件.如果没有配置文件处于活动状态,则所有测试都将使用mvn test
运行(我希望这就是您想要的)
What i have done in some of our projects, is to use <profiles>
in the pom.xml
to activate special suites of tests. If no profiles are active, all tests will be run with mvn test
(i hope that's what you are looking for)
像这样:
<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>
以注释方式测试类,如下所示:
Test classes in annotated like so:
@Category(CommitTest.class)
public class SomeTestClass {
}
我不知道它是否可以与@Suite
和@RunWith
一起使用,但是如果您的测试套件没有太多的类,那么更改它应该不是一件容易的事.
I don't know if it works with @Suite
and @RunWith
but if your test suites aren't too many classes, it shouldn't be a difficult job to change that.
命令:mvn clean test -Pcommit-test
这篇关于Maven Surefire Junit测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!