Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Produce tree output with Surefire like the JUnit 5 console launcher

Tags:

java

junit5

The Console Launcher that comes with JUnit Platform (from JUnit 5) produces a quite nice summary view at the end. The Maven Surefire plugin, however, has a very simple output.

Is it possible to create with Surefire output similar to what the launches creates?

like image 723
Michael Piefel Avatar asked Jun 06 '18 14:06

Michael Piefel


People also ask

How do I run a JUnit 5 test in Maven?

We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.

Is it possible to use JUnit 4 and JUnit 5 tests in the same test project or suite )?

JUnit 5 provides a way out of the box. Each one is a distinct project and using all of them allows to compile and execute JUnit 4 and JUnit 5 tests in a same project.

What is JUnit platform launcher?

platform. launcher. Public API for configuring and launching test plans. This API is typically used by IDEs and build tools.

What JUnit 5?

JUnit 5 is the next generation of JUnit. The goal is to create an up-to-date foundation for developer-side testing on the JVM. This includes focusing on Java 8 and above, as well as enabling many different styles of testing. JUnit 5 is the result of JUnit Lambda and its crowdfunding campaign on Indiegogo.


1 Answers

My current workaround is to disable surefire and use exec-maven-plugin to manually run ConsoleLauncher:

<!-- disable surefire -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version><!-- ... --></version>
  <executions>
    <execution>
      <id>default-test</id>
      <phase>none</phase>
    </execution>
  </executions>
</plugin>
<!-- enable ConsoleLauncher -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version><!-- ... --></version>
  <executions>
    <execution>
      <phase>test</phase>
      <goals><goal>java</goal></goals>
      <configuration>
        <mainClass>org.junit.platform.console.ConsoleLauncher</mainClass>
        <arguments>
          <argument>--scan-class-path</argument>
          <argument>${project.build.directory}/test-classes</argument>
        </arguments>
        <classpathScope>test</classpathScope>
      </configuration>
    </execution>
  </executions>
</plugin>
<!-- ... -->
<dependency>
  <groupId>org.junit.platform</groupId>
  <artifactId>junit-platform-console-standalone</artifactId>
  <version><!-- ... --></version>
  <scope>test</scope>
</dependency>
like image 110
rampion Avatar answered Oct 17 '22 10:10

rampion