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

Important: This document includes references to a third-party product, TestWatcher. The user interface and usage of third-party products are subject to change without notice. For the latest published information about TestWatcher, see https://junit.org/junit5/docs/5.5.1/api/org/junit/jupiter/api/extension/TestWatcher.html.

Prerequisites

Integrating TestWatcher with Perfecto requires:

1 | Set up the integration

  1. Clone or download the following repository: https://github.com/PerfectoMobileSA/Junit5TestWatcherSample

  2. After downloading and extracting the project to your computer, open it from your IDE by selecting the folder containing the pom.xml file.

  3. Open TestBase.java.

  4. Find the following line and replace <<cloud name>> with the name of your Perfecto cloud, for example demo.

    Copy
    String cloudName = "<<cloud name>>"
  5. Find the following line and replace <<SECURITY TOKEN>> with your Perfecto security token

    Copy
    String 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).

3 | Integrate with your existing Maven project

If you have an existing Maven project, follow these steps to integrate with it.

  1. 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>
  2. Extend your test base class with the following annotation:

    Copy
    @ExtendWith(PerfectoWatcher.class)
  3. 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.