Java Surefire不排除标有@Tag的JUnit 5测试

Java Surefire不排除标有@Tag的JUnit 5测试,java,junit5,Java,Junit5,我有一个JUnit5测试,有两种测试方法。一个用标记“slow”注释,另一个用标记“fast”注释。我还使用excludetag配置了SureFire插件,这样它就可以忽略带有“slow”标记的测试 我希望在这种设置下,只执行带有“fast”标记的测试,但在我的情况下,两者都是。似乎@Tag注释根本没有效果 以下是测试类: package junit5; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test;

我有一个JUnit5测试,有两种测试方法。一个用标记“slow”注释,另一个用标记“fast”注释。我还使用excludetag配置了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>
正如您所看到的,两个测试用例都已运行


根据我对文档的理解,我已经正确地设置了所有内容。我遗漏了什么?

这个问题是由maven surefire插件在JDK 9上运行时的一个错误引起的:

maven surefire插件在使用JDK 9运行时似乎有一个错误:它不会将属性传递给surefire提供程序。我将向他们提出一个问题。与此同时,你能试着用JDK 8运行吗?@Marchphilipp我仍然想知道(在接受了答案之后),java 9是如何出现在这里的?上面pom中的目标和源都设置为“9”。我调试了maven surefire插件并找到了中所述的根本原因。这只发生在JDK 9上,
Properties
的实现显然发生了变化。我似乎也遇到了同样的问题,但使用JDK8看起来像是典型的脆弱基类问题;-)
> 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] ------------------------------------------------------------------------