Dan*_*SFT 6 java junit maven junit5
我刚刚升级了我的解决方案以使用JUnit5.现在尝试为我的测试创建具有两个标签的标签:@Fast
和@Slow
.首先,我使用下面的maven条目来配置使用我的默认构建运行的测试.这意味着当我执行时,mvn test
我的快速测试将执行.我假设我可以使用命令行覆盖它.但我无法弄清楚我要进入慢速测试的内容......
我假设像...... mvn test -Dmaven.IncludeTags=fast,slow
这样的东西不起作用
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<properties>
<includeTags>fast</includeTags>
<excludeTags>slow</excludeTags>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M3</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Nik*_*s P 12
你可以这样使用:
<properties>
<tests>fast</tests>
</properties>
<profiles>
<profile>
<id>allTests</id>
<properties>
<tests>fast,slow</tests>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<properties>
<includeTags>${tests}</includeTags>
</properties>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
这样您就可以开始mvn -PallTests test
所有测试(甚至是mvn -Dtests=fast,slow test
).
使用配置文件是可能的,但它不是强制性的,groups
并且maven surefire插件中excludedGroups
定义的用户属性分别包含和排除任何JUnit 5标记(并且它也适用于JUnit 4和TestNG测试过滤机制).
因此,要执行标记测试或者你可以运行:slow
fast
mvn test -Dgroups=fast,slow
Run Code Online (Sandbox Code Playgroud)
如果要在Maven配置文件中定义排除和/或包含的标记,则无需声明新属性来传达它们,并在maven surefire插件中将它们关联起来.只需使用groups
和或excludedGroups
通过Maven的万无一失插件定义和期望:
<profiles>
<profile>
<id>allTests</id>
<properties>
<groups>fast,slow</groups>
</properties>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
您可以省略配置文件,只使用属性,这是更有弹性的方式。
<properties>
<tests>fast</tests>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<groups>${tests}</groups>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
然后,您可以通过键入进行快速测试mvn test
、通过键入进行所有测试mvn test -Dtests=fast | slow
或仅通过键入进行慢速测试mvn test -Dtests=slow
。当您有更多测试标签时,您还可以通过键入 来运行除所选类型之外的所有测试标签mvn test -Dtests="! contract"
。
归档时间: |
|
查看次数: |
6049 次 |
最近记录: |