How to choose which JUnit5 Tags to execute with Maven
You can use this way:
<properties>
<tests>fast</tests>
</properties>
<profiles>
<profile>
<id>allTests</id>
<properties>
<tests>fast,slow</tests>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<groups>${tests}</groups>
</configuration>
</plugin>
</plugins>
</build>
This way you can start with mvn -PallTests test
all tests (or even with mvn -Dtests=fast,slow test
).
Using a profile is a possibility but it is not mandatory as groups
and excludedGroups
are user properties defined in the maven surefire plugin to respectively include and exclude any JUnit 5 tags (and it also works with JUnit 4 and TestNG test filtering mechanism).
So to execute tests tagged with slow
or fast
you can run :
mvn test -Dgroups=fast,slow
If you want to define the excluded and/or included tags in a Maven profile you don't need to declare a new property to convey them and to make the association of them in the maven surefire plugin. Just use groups
and or excludedGroups
defined and expected by the maven surefire plugin :
<profiles>
<profile>
<id>allTests</id>
<properties>
<groups>fast,slow</groups>
</properties>
</profile>
</profiles>