Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fabriciorby/maven-surefire-junit5-tree-reporter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.0
Choose a base ref
...
head repository: fabriciorby/maven-surefire-junit5-tree-reporter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.0
Choose a head ref
  • 6 commits
  • 16 files changed
  • 2 contributors

Commits on Jun 20, 2022

  1. Copy the full SHA
    55713ce View commit details

Commits on Jun 26, 2022

  1. Add more samples for testing (#8)

    Add new tests and update Junit version
    fabriciorby authored Jun 26, 2022
    Copy the full SHA
    fdb3166 View commit details

Commits on Jun 27, 2022

  1. Copy the full SHA
    45b8ead View commit details
  2. Update maven-publish.yml

    fabriciorby authored Jun 27, 2022
    Copy the full SHA
    f88c1aa View commit details
  3. Fixes #9 - Printing Nested Tests Accordingly (#10) (#11)

    * Create TreePrinter
    * Create Unit Test (needs improvement)
    * Create Themes (ASCII and UNICODE)
    * Added Mockito
    * Update README.md
    fabriciorby authored Jun 27, 2022
    Copy the full SHA
    dd18df7 View commit details
  4. Version 1.0.0

    fabriciorby committed Jun 27, 2022
    Copy the full SHA
    983d67e View commit details
42 changes: 42 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path

name: Maven Deploy Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'

- name: Build with Maven
run: mvn -B package --file pom.xml --no-transfer-progress --batch-mode

- name: Set up Apache Maven Central
uses: actions/setup-java@v3
with: # running setup-java again overwrites the settings.xml
distribution: 'temurin'
java-version: '11'
cache: 'maven'
server-id: maven-central # Value of the distributionManagement/repository/id field of the pom.xml
server-username: MAVEN_USERNAME # env variable for username in deploy
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Publish to Apache Maven Central
run: mvn deploy --no-transfer-progress --batch-mode
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -28,3 +28,5 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

settings.xml
62 changes: 53 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,87 @@
# Maven Surefire JUnit5 TreeView Extension

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](https://maven.apache.org/surefire/maven-surefire-plugin/), it adds a tree view for the unit tests executed using JUnit5.

## Output

It's in WIP yet, but the output is something like this:
The output can be printed in two ways.

### UNICODE
![Imgur](https://i.imgur.com/tgV2mse.png "UNICODE Output")
``org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode``

![alt text](https://i.imgur.com/qMb4eoC.png "output")
### ASCII
![Imgur](https://imgur.com/nwo1C0F.png "ASCII Output")
``org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter``

## Installation

The Maven Repository can be found [here](https://mvnrepository.com/artifact/me.fabriciorby/maven-surefire-junit5-tree-reporter).

Just let your pom.xml be like this.
Configure your POM like the following

### UNICODE Output

```xml
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
<version>3.0.0-M7</version>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>0.2.0</version>
<version>0.3.0-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<reportFormat>plain</reportFormat>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode">
</statelessTestsetInfoReporter>
</configuration>
</plugin>
```

The important thing here is to set ``reportFormat`` as ``plain``, disable the console output and use our new class ``JUnit5StatelessTestsetInfoTreeReporter`` to print the results.
### ASCII Output

## Known bugs
```xml
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>0.3.0-SNAPSHOT</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 maven-sunfire-plugin doesn't handle ``@Nested`` tests in the desired order so our result tree is not perfect yet. I've forked the maven-sunfire project and debugged it but still couldn't figure out how to solve this my myself...
## Contribute

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](src/main/java/org/apache/maven/plugin/surefire/report/Theme.java) Enum, feel free to open a PR.

### Debugging

If you ever want to debug the code, please use the following command
```
mvnDebug test
```
Then attach a remote JVM debugger on port 8000
47 changes: 41 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -6,30 +6,35 @@

<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>0.2.0</version>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>maven-surefire-junit5-tree-reporter</name>
<description>Tree view reports for Maven Surefire JUnit5 plugin. :^)</description>
<url>https://github.com/fabriciorby/maven-surefire-junit5-tree-reporter</url>

<properties>
<junit-jupiter-api.version>5.8.2</junit-jupiter-api.version>
<junit-jupiter.version>5.9.0-M1</junit-jupiter.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.surefire.version>3.0.0-M6</maven.surefire.version>
<maven.surefire.version>3.0.0-M7</maven.surefire.version>
<maven-surefire.testsetInfoReporter>
org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode
</maven-surefire.testsetInfoReporter>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<mockito.version>4.6.1</mockito.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-api.version}</version>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -38,6 +43,18 @@
<version>${maven.surefire.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<licenses>
@@ -94,7 +111,8 @@
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<statelessTestsetInfoReporter
implementation="${maven-surefire.testsetInfoReporter}">
</statelessTestsetInfoReporter>
</configuration>
</plugin>
@@ -149,9 +167,26 @@
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${nexus-staging-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>maven-central</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -21,15 +21,9 @@

import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.report.ConsoleTreeReporter;
import org.apache.maven.plugin.surefire.report.FileReporter;
import org.apache.maven.plugin.surefire.report.TestSetStats;
import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoFileReportEventListener;

import java.io.File;
import java.nio.charset.Charset;


/**
* Extension of {@link JUnit5StatelessTestsetInfoReporter file and console reporter of test-set} for JUnit5.
@@ -47,41 +41,10 @@ public StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSe
isUsePhrasedClassNameInTestCaseSummary() );
}

@Override
public StatelessTestsetInfoFileReportEventListener<WrappedReportEntry, TestSetStats> createListener(
File reportsDirectory, String reportNameSuffix, Charset encoding )
{
return new FileReporter( reportsDirectory, reportNameSuffix, encoding, isUsePhrasedFileName(),
isUsePhrasedClassNameInRunning(), isUsePhrasedClassNameInTestCaseSummary() );
}

@Override
public Object clone( ClassLoader target )
{
try
{
Object clone = super.clone( target );

Class<?> cls = clone.getClass();
cls.getMethod( "setUsePhrasedFileName", boolean.class )
.invoke( clone, isUsePhrasedFileName() );
cls.getMethod( "setUsePhrasedClassNameInTestCaseSummary", boolean.class )
.invoke( clone, isUsePhrasedFileName() );
cls.getMethod( "setUsePhrasedClassNameInRunning", boolean.class )
.invoke( clone, isUsePhrasedFileName() );

return clone;
}
catch ( ReflectiveOperationException e )
{
throw new IllegalStateException( e.getLocalizedMessage() );
}
}

@Override
public String toString()
{
return "JUnit5StatelessTestsetInfoReporterCustom{"
return "JUnit5StatelessTestsetInfoTreeReporter{"
+ "disable=" + isDisable()
+ ", usePhrasedFileName=" + isUsePhrasedFileName()
+ ", usePhrasedClassNameInRunning=" + isUsePhrasedClassNameInRunning()
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.apache.maven.plugin.surefire.extensions.junit5;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.report.*;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;

/**
* Extension of {@link JUnit5StatelessTestsetInfoReporter file and console reporter of test-set} for JUnit5.
*
* @author <a href="mailto:fabriciorby@hotmail.com">Fabrício Yamamoto (fabriciorby)</a>
*/
public class JUnit5StatelessTestsetInfoTreeReporterUnicode extends JUnit5StatelessTestsetInfoTreeReporter
{

@Override
public StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> createListener(
ConsoleLogger logger )
{
return new ConsoleTreeReporterUnicode( logger, isUsePhrasedClassNameInRunning(),
isUsePhrasedClassNameInTestCaseSummary() );
}

@Override
public String toString()
{
return "JUnit5StatelessTestsetInfoTreeReporterUnicode{"
+ "disable=" + isDisable()
+ ", usePhrasedFileName=" + isUsePhrasedFileName()
+ ", usePhrasedClassNameInRunning=" + isUsePhrasedClassNameInRunning()
+ ", usePhrasedClassNameInTestCaseSummary=" + isUsePhrasedClassNameInTestCaseSummary()
+ "}";
}
}
Loading