If you are a Maven Surefire user and ever wanted a fancy tree output for your tests instead of a bunch of logs, you absolutely should try this.
This is a dependency for maven-surefire-plugin, it adds a tree view for the unit tests executed using JUnit5.
The Maven Repository can be found here.
Configure your POM like the following
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.1</version>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<configuration>
<reportFormat>plain</reportFormat>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
</statelessTestsetInfoReporter>
</configuration>
</plugin>
The output can be printed using two Themes: UNICODE and ASCII (by default).
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<theme>UNICODE</theme>
</statelessTestsetInfoReporter>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<theme>ASCII</theme>
</statelessTestsetInfoReporter>
Output in large projects could become too verbose, making failures or errors difficult to find inside the printed trees. To reduce verbosity, you can a hide successful results option can be configured as follows:
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<hideResultsOnSuccess>true</hideResultsOnSuccess>
</statelessTestsetInfoReporter>
By default, <consoleOutputReporter><disable>true</disable></consoleOutputReporter>
disables all console output. To debug test failures, it may be useful to see the console output and stack traces when a test fails. To do so, you can configure this extension like this:
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<printStacktraceOnError>true</printStacktraceOnError>
<printStacktraceOnFailure>true</printStacktraceOnFailure>
<printStdoutOnError>true</printStdoutOnError>
<printStdoutOnFailure>true</printStdoutOnFailure>
<printStdoutOnSuccess>false</printStdoutOnSuccess>
<printStderrOnError>true</printStderrOnError>
<printStderrOnFailure>true</printStderrOnFailure>
<printStderrOnSuccess>false</printStderrOnSuccess>
</statelessTestsetInfoReporter>
You are welcome to contribute to the project, for this just open an issue or issue + PR to develop
branch.
If you want to create your own output based on the Theme Enum, feel free to open a PR.
If you ever want to debug the code, please use the following command
mvnDebug test
Then attach a remote JVM debugger on port 8000
This SurefireEmulator class was developed so it's easier to debug the code.
new SurefireEmulator(NestedExampleTest.class).run();
By running this command it's possible to debug the code almost as the actual Surefire was running. And it also returns a List with all the lines that were printed during the test execution.