Junit 5 TestWatcher
Perfecto integrates with JUnit 5 TestWatcher. TestWatcher defines the API for extensions that want to process test results. For more information on TestWatcher, see Interface TestWatcher.
Perfecto provides a sample Maven and Java project that showcases the Junit 5 TestWatcher integration with Perfecto Smart Reporting. Learn how to implement this integration. The sample project is available on GitHub: https://github.com/PerfectoMobileSA/Junit5TestWatcherSample
On this page:
Prerequisites
Integrating TestWatcher with Perfecto requires:
- Java 8
- An IDE to write your tests in, such as Eclipse or IntelliJ
- Maven
- The Maven plugin for the IDE used:
1 | Set up the integration
-
Clone or download the following repository: https://github.com/PerfectoMobileSA/Junit5TestWatcherSample
-
After downloading and extracting the project to your computer, open it from your IDE by selecting the folder containing the
pom.xml
file. -
Open
TestBase.java
. -
Find the following line and replace
<<cloud name>>
with the name of your Perfecto cloud, for example demo.CopyString cloudName = "<<cloud name>>";
-
Find the following line and replace <<SECURITY TOKEN>> with your Perfecto security token:
CopyString securityToken = "<<SECURITY TOKEN>>";
You can also pass the security token as maven properties, as follows:
Copy-DsecurityToken=<<SECURITY TOKEN>>
2 | Execute the project
You can execute the project locally or through continuous integration (CI).
To integrate with the CI Dashboard in Perfecto Smart Reporting, supply the following parameters:
clean
install
test
-DcloudName=${cloudName}
-DsecurityToken=${securityToken}
-Dreportium-job-name=${JOB_NAME}
-Dreportium-job-number=${BUILD_NUMBER}
-Dreportium-job-branch=${GIT_BRANCH}
-Dreportium-tags=${myTag}
For more information, see Integrate Smart Reporting with CI tools.
3 | Integrate with your existing Maven project
If you have an existing Maven project, follow these steps to integrate with it.
-
Add the following maven dependencies:
Copy<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.5.2</version></dependency><dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-runner</artifactId> <version>1.5.2</version></dependency>
-
Extend your test base class with the following annotation:
Copy@ExtendWith(PerfectoWatcher.class)
- Import this class to your project and change the package name, test base class name, driver, and reportiumClient object as applicable.
Sample results
Following is a TestWatcher sample result.
In Perfecto Smart Reporting, the Single Test Report looks as follows.