maventestingtagsjunit5maven-surefire-plugin

Maven: exclude/include tests by tag, some test methods are not tagged


I am confused by the so many partial answers to my question: with maven, junit5 and surefire plugin (all latest versions), how to run those tests with a specific tag (e.g. networkaccess and run all those tests without this tag, or possibly with no tags at all, by default.

By default, most of my test methods are not tagged. There are few which are tagged: @Tag(networkaccess).

I need to know how to run those tests with the specified tag. ANd how to run those tests without the specified tag. In the latter case test methods may not have @Tag(...) at all.

I am using the command line without any IDE.


Solution

  • Ensure that you are using maven-surefire-plugin 2.22.0+, then run

    mvn test -Dgroups=networkaccess
    

    or

    mvn test -DexcludedGroups=networkaccess