我有两个测试方法的JUnit 5测试。一个用标签“slow”注释,另一个用标签“fast”注释。我还使用excludeTags配置了SureFire插件,它应该忽略带有“slow”标签的测试。
我希望通过这种设置,只会执行带有“fast”标签的测试,但在我的情况下,两者都是。似乎@Tag注释根本没有效果。
这是测试类:
package junit5;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
class TaggingTest {
@Tag("fast")
@Test
void fast() {
System.out.println("*** fast ***");
}
@Tag("slow")
@Test
void slow() {
System.out.println("*** slow ***");
}
}
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>junit5</groupId>
<artifactId>tagging</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<properties>
<excludeTags>slow</excludeTags>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
当我运行mvn test时,我得到了这个输出:
> mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building tagging 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ tagging ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ tagging ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ tagging ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/olaf.prins/temp/junit-tagging/tagging/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ tagging ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/olaf.prins/temp/junit-tagging/tagging/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default-test) @ tagging ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running junit5.TaggingTest
*** fast ***
*** slow ***
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.049 sec - in junit5.TaggingTest
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.800 s
[INFO] Finished at: 2017-11-15T16:36:14+01:00
[INFO] Final Memory: 13M/512M
[INFO] ------------------------------------------------------------------------
正如您所看到的,两个测试用例都已运行。
据我了解文档,我已正确设置了所有内容。我错过了什么?
答案 0 :(得分:4)
此问题是由maven-surefire-plugin在JDK 9上运行时的错误引起的:https://issues.apache.org/jira/browse/SUREFIRE-1445