Junit5: Can't exclude tags with Maven Surefire via command line options

Created on 2 Oct 2018  路  9Comments  路  Source: junit-team/junit5

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
Maven Surefire question

All 9 comments

Assuming you're using Surefire 2.22.0, you may exclude tags via excludedGroups.

For details see https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html

Assuming you're using Surefire 2.22.0, you may exclude tags via excludedGroups.

For details see https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html

Yeah, but in this case i have to make two profiles with different exclude/include Tags :(

That's how Maven/Surefire works. Perhaps StackOverflow is a better place to ask Surefire configuration/setup related questions. Their might be a solution to your task. :)

Yeah, but in this case i have to make two profiles with different exclude/include Tags :(

Have you tried using a tag expression instead of just simple tags?

Closing this issue since the JUnit team no longer maintains the Maven Surefire provider.

Yeah, but in this case i have to make two profiles with different exclude/include Tags :(

Have you tried using a tag expression instead of just simple tags?

Yep, it's solution, thnx
mvn clean test -Dtest="/selftest/" -Dgroups=!NotThreadSafe

You're welcome.

Glad that works for you!

And thanks for letting us know.

I have the same issue and just specifying -Dgroups should work, according to the documentation, but it does not, not sure why you need to specify -Dtest here

Putting in single quotes works for me:
mvn clean test '-Dgroups=!category'

Was this page helpful?
0 / 5 - 0 ratings