TestReporterParameterResolver

The last built-in resolver in JUnit 5 is TestReporterParameterResolver. Again, given a test class, if a method parameter is of type TestReporter, the TestReporterParameterResolver  supplies an instance of TestReporter.

TestReporter is used to publish additional data about the test execution. The data can be consumed through the method reportingEntryPublished, and then, it can be requested by IDEs or included in test reports. Each TestReporter object stores information as a map, that is, a key-value collection:

TestReporter API

This test provides a simple example of TestReporter. As we can see, we use the injected testReporter object to add custom information using key-value pairs:

package io.github.bonigarcia;

import java.util.HashMap;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestReporter;

class TestReporterTest {

@Test
void reportSingleValue(TestReporter testReporter) {
testReporter.publishEntry("key", "value");
}

@Test
void reportSeveralValues(TestReporter testReporter) {
HashMap<String, String> values = new HashMap<>();
values.put("name", "john");
values.put("surname", "doe");
testReporter.publishEntry(values);
}

}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.34.146