I have multiple Junit test suites (SlowTestSuite, FastTestSuite etc). I would like to run only specific suite using maven command. e.g.
我有多个Junit测试套件(SlowTestSuite,FastTestSuite等)。我想使用maven命令只运行特定的套件。例如
mvn clean install test -Dtest=FastTestSuite -DfailIfNoTests=false
but its not working. Just not running any test at all. Any suggestions please.
但它不起作用。根本就没有运行任何测试。请给我任何建议。
2 个解决方案
#1
37
I have achieved this by adding property into pom as:
我通过将属性添加到pom中来实现此目的:
<properties>
<runSuite>**/FastTestSuite.class</runSuite>
</properties>
and maven-surefire-plugin should be:
和maven-surefire-plugin应该是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
</configuration>
</plugin>
so it means by default it will run FastTestSuite but you can run other test e.g. SlowTestSuite using maven command as:
所以它默认意味着它将运行FastTestSuite,但你可以运行其他测试,例如SlowTestSuite使用maven命令:
mvn install -DrunSuite=**/SlowTestSuite.class -DfailIfNoTests=false
#2
5
The keyword you missed is maven-surefire-plugin :http://maven.apache.org/plugins/maven-surefire-plugin/.
您错过的关键字是maven-surefire-plugin:http://maven.apache.org/plugins/maven-surefire-plugin/。
Usage is :
用法是:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<includes>
<include>**/com.your.packaged.Sample.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
If you make a little search on stack overflow, you may find information :
如果您对堆栈溢出进行一些搜索,您可能会找到以下信息:
Running a JUnit4 Test Suite in Maven using maven-failsafe-plugin Using JUnit Categories with Maven Failsafe plugin
使用maven-failsafe-plugin在Maven中运行JUnit4测试套件使用带有Maven Failsafe插件的JUnit类别
In addition, you may define profile, like fastTest, that will be triggered by adding parameter to cmd line :
此外,您可以定义配置文件,如fastTest,将通过向cmd行添加参数来触发:
mvn package -PfastTests
This profile would include some inclusions too.
此配置文件也包含一些内容。
#1
37
I have achieved this by adding property into pom as:
我通过将属性添加到pom中来实现此目的:
<properties>
<runSuite>**/FastTestSuite.class</runSuite>
</properties>
and maven-surefire-plugin should be:
和maven-surefire-plugin应该是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
</configuration>
</plugin>
so it means by default it will run FastTestSuite but you can run other test e.g. SlowTestSuite using maven command as:
所以它默认意味着它将运行FastTestSuite,但你可以运行其他测试,例如SlowTestSuite使用maven命令:
mvn install -DrunSuite=**/SlowTestSuite.class -DfailIfNoTests=false
#2
5
The keyword you missed is maven-surefire-plugin :http://maven.apache.org/plugins/maven-surefire-plugin/.
您错过的关键字是maven-surefire-plugin:http://maven.apache.org/plugins/maven-surefire-plugin/。
Usage is :
用法是:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<includes>
<include>**/com.your.packaged.Sample.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
If you make a little search on stack overflow, you may find information :
如果您对堆栈溢出进行一些搜索,您可能会找到以下信息:
Running a JUnit4 Test Suite in Maven using maven-failsafe-plugin Using JUnit Categories with Maven Failsafe plugin
使用maven-failsafe-plugin在Maven中运行JUnit4测试套件使用带有Maven Failsafe插件的JUnit类别
In addition, you may define profile, like fastTest, that will be triggered by adding parameter to cmd line :
此外,您可以定义配置文件,如fastTest,将通过向cmd行添加参数来触发:
mvn package -PfastTests
This profile would include some inclusions too.
此配置文件也包含一些内容。