callmedope
callmedope

Reputation: 83

How to exclude tags with Maven Surefire via command line options?

I'm trying to exclude a tag from test execution with Java system props that are passed via the command line, but it's not working.

public class A {

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

    @Test
    public void test2(){
        System.out.println("It's ok");
    }
}

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

Output:

NotThreadSafe
It's ok

But -Dgroups propery works fine:

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

Output:

NotThreadSafe

Upvotes: 2

Views: 4579

Answers (1)

callmedope
callmedope

Reputation: 83

As mentioned here: https://github.com/junit-team/junit5/issues/1612#issuecomment-426217199

We need to use Tag expressions

mvn clean test -Dtest="**/selftest/**" -Dgroups=\!NotThreadSafe

Upvotes: 5

Related Questions