Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Junit5: TestReporterParameterResolver: Get data about current test run

If a constructor or method parameter is of type Testreporter, the TestReporterParameterResolver will supply an instance of TestReporter. The TestReporter can be used to publish additional data about the current test run.

 

Find the below working applications.

 

TestReporterDemo.java

package com.sample.app;

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestReporter;

public class TestReporterDemo {
@Test
void reportSingleValue(TestReporter testReporter) {
System.out.println("\nInside reportSingleValue method");
testReporter.publishEntry("a status message");
}

@Test
void reportKeyValuePair(TestReporter testReporter) {
System.out.println("\nInside reportKeyValuePair method");
testReporter.publishEntry("methodName", "reportKeyValuePair");
}

@Test
void reportMultipleKeyValuePairs(TestReporter testReporter) {
System.out.println("\nInside reportMultipleKeyValuePairs method");

Map values = new HashMap();
testReporter.publishEntry("methodName", "reportMultipleKeyValuePairs");
testReporter.publishEntry("demo", "TestReporter");

testReporter.publishEntry(values);
}
}

Run above test class, you will see below messages in console.

Inside reportSingleValue method
TestIdentifier [reportSingleValue(TestReporter)]
ReportEntry [timestamp = 2020-07-04T12:35:26.408, value = 'a status message']

Inside reportMultipleKeyValuePairs method
TestIdentifier [reportMultipleKeyValuePairs(TestReporter)]
ReportEntry [timestamp = 2020-07-04T12:35:26.416, methodName = 'reportMultipleKeyValuePairs']
TestIdentifier [reportMultipleKeyValuePairs(TestReporter)]
ReportEntry [timestamp = 2020-07-04T12:35:26.416, demo = 'TestReporter']
TestIdentifier [reportMultipleKeyValuePairs(TestReporter)]
ReportEntry [timestamp = 2020-07-04T12:35:26.416]

Inside reportKeyValuePair method
TestIdentifier [reportKeyValuePair(TestReporter)]
ReportEntry [timestamp = 2020-07-04T12:35:26.418, methodName = 'reportKeyValuePair']


Junit test report window is given below.




 

  

Previous                                                    Next                                                    Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Junit5: TestReporterParameterResolver: Get data about current test run

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×