Search code examples
junitjunit4junit5

How to create a maven build with junit-jupiter and junit-vintage profile


I am trying to set up a maven build with two build profiles

  • one with junit-jupiter (JUnit 5)
  • one with junit-vintage (Junit 4)

The default profile is using the junit-jupiter-engigne and is working as expected, but the vintage profile (which are using the unit-vintage-engine) will not discover any tests...

The default profile, just run maven: mvn test
The vintage profile, run maven with property: mvn test -Dtest=vintage

Can anyone see what is wrong with the configuration in this simple project which only contains one class and two junit tests (one junit-jupiter and one junit (v 4.13.1) https://github.com/jactor-rises/junit-profiles

Note!
The main branch do not contain any code.
There are two implementations, see branches: feature/java and feature/kotlin


Solution

  • You cannot use property with the name "test" with maven-surefire-plugin for activating the profile because it's predefined for running a single test.

    Rename it to something else.

    Also, you can use -P instead: mvn test -P vintage.