Runing test from jar with Junit5

java -jar junit-platform-console-standalone-1.3.0-M1.jar -n .*IT -scan-class-path -cp target\test-classes\(test.jar) -cp target\app-jar-with-dependencies.jar
where:
  • -n .*IT is a regex looking for files suffixed with IT (default: ^(Test.*|.+[.$]Test.*|.*Tests?)$)
  • -scan-class-path look for tests on classpath
  • -cp: the classpath

Bonus:

to compile test classes:  mvn test-compile compile

to create test jar:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Leave a Reply