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<String, String> 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
No comments:
Post a Comment