ReportPortal JUnit 5 Extension
A JUnit 5 reporter that uploads the results to a ReportPortal server.
DISCLAIMER: We use Google Analytics for sending anonymous usage information such as agent's and client's names, and their versions
after a successful launch start. This information might help us to improve both ReportPortal backend and client sides. It is used by the
ReportPortal team only and is not supposed for sharing with 3rd parties.
The latest version: 5.5.8. Please use Maven Central link above to get the client.
ReportPortal JUnit5 Integration
The repository contains JUnit5 Extension for ReportPortal integration.
Getting Started
To start using ReportPortal with JUnit 5 create a service location file:
- Create folders /META-INF/services in resources
- Put there a file named **org.junit.jupiter.api.extension.Extension**ы
- Put a default implementation reference as a single row into the file: com.epam.reportportal.junit5.ReportPortalExtension
Example:
/META-INF/services/org.junit.jupiter.api.extension.Extension
com.epam.reportportal.junit5.ReportPortalExtension
If you desire to configure test name, description and tags:
Extend ReportPortalExtension, override buildStartStepRq() or other methods (see javadoc comments) and replace
com.epam.reportportal.junit5.ReportPortalExtension with fully qualified custom Extension class name in this file.
Maven
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>agent-java-junit5</artifactId>
<version>5.5.8</version>
</dependency>
Automatic Extension Registration (optional)
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
</build>
Gradle
repositories {
mavenLocal()
mavenCentral()
}
testImplementation 'com.epam.reportportal:agent-java-junit5:5.5.8'
Automatic Extension Registration (optional)
test {
useJUnitPlatform()
systemProperty 'junit.jupiter.extensions.autodetection.enabled', true
}
Disabled tests reporting
By default reporting of @Disabled tests is switched off. To switch it on - add next parameter to an execution goal:
- Maven: -DreportDisabledTests=true
- Gradle: -PreportDisabledTests=true
Step-by-step integration manual for JUnit5
This manual will walk you through the steps for integration of ReportPortal with JUnit5 based project
First, make sure you have installed ReportPortal, the installation steps could be found here
We’ll assume that ReportPortal is installed and running on http://localhost:8080
Step 1 - Create new project (Maven)
If you want to integrate ReportPortal with existing project, go to step 2
1.1 Start new maven project

1.2 Enter GroupId and ArtifactId

1.3 Enter project name

Step 2 - Configure pom.xml
2.1 Add following dependencies:
ReportPortal agent implementation for JUnit 5
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>agent-java-junit5</artifactId>
<version>5.5.8</version>
</dependency>
Latest version of the agent, could be found here
The ReportPortal agent for JUnit 5 includes the JUnit 5 library dependency, and so we won't need other explicit JUnit 5 dependencies
However, if you are adding ReportPortal agent to existing project, with JUnit 5 dependency already declared, pay attention to dependency transitivity and the conflicts that might arise
More about JUnit 5 dependencies structure could be found here
2.2 Add ReportPortal dedicated logger wrapper
ReportPortal provides its own logger implementations for major logging frameworks like log4j and logback
If you prefer using Logback logging library, add following dependencies:
ReportPortal logback logger dependency
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>logger-java-logback</artifactId>
<version>5.2.2</version>
</dependency>
Up to date version could be found here
The logback itself
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.10</version>
</dependency>
If you prefer using Log4j logging library, add following dependencies:
ReportPortal log4j logger dependency
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>logger-java-log4j</artifactId>
<version>5.2.2</version>
</dependency>
Up to date version could be found here
The log4j itself
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
Step 3 - Add the test with logging
3.1 Add simple test method
Create a test class MyTests in the test directory and add JUnit 5 test method there
package com.mycompany.tests;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.*;
public class MyTests {
private static final Logger LOGGER = LogManager.getLogger(MyTests.class);
@Test
void testMySimpleTest() {
LOGGER.info("Hello from my simple test");
}
}
3.2 Add log4j2.xml file to resources folder
Example:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout
pattern="%d [%t] %-5level %logger{36} - %msg%n%throwable"/>
</Console>
<ReportPortalLog4j2Appender name="ReportPortalAppender">
<PatternLayout
pattern="%d [%t] %-5level %logger{36} - %msg%n%throwable"/>
</ReportPortalLog4j2Appender>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="ConsoleAppender"/>
<AppenderRef ref="ReportPortalAppender"/>
</Root>
</Loggers>
</Configuration>
It's needed to add ReportPortalAppender into this (as shown in the example)
By this moment, your project tree should look somewhat like the this:

Step 4 - Configuring ReportPortal
4.1 Open ReportPortal UI
Go to http:$IP_ADDRESS_OF_REPORT_PORTAL:8080 (by default it is http://localhost:8080)
Login as Admin user and create the project (more details here and here)


4.2 Add users to your project:
Go to Administrative -> My Test Project -> Members -> Add user
Example link http://localhost:8080/ui/#administrate/project-details/my_test_project/members

Step 5 - Link ReportPortal with your tests
5.1 - Add reportportal.properties