如何通过命令行选项使用 Maven Surefire 排除标签?

cal*_*ope 2 java maven-surefire-plugin junit5

我试图使用通过命令行传递的 Java 系统属性从测试执行中排除标签,但它不起作用。

public class A {

    @Test
    @Tag("NotThreadSafe")
    public void test(){
        System.out.println("NotThreadSafe");
    }

    @Test
    public void test2(){
        System.out.println("It's ok");
    }
}
Run Code Online (Sandbox Code Playgroud)

$: mvn clean test -Dtest="**/selftest/**" -DexcludeTags="NotThreadSafe"

输出:

NotThreadSafe
It's ok
Run Code Online (Sandbox Code Playgroud)

但 -Dgroups 属性工作正常:

$: mvn clean test -Dtest="**/cdp/autotests/selftest/**" -Dgroups="NotThreadSafe"

输出:

NotThreadSafe
Run Code Online (Sandbox Code Playgroud)

cal*_*ope 5

正如这里提到的: https://github.com/junit-team/junit5/issues/1612#issuecomment-426217199

我们需要使用标签表达式

mvn clean test -Dtest="**/selftest/**" -Dgroups=\!NotThreadSafe
Run Code Online (Sandbox Code Playgroud)