How to include additional information in OTR report and include it in HTML report using open-test-reporting-cli #4175
-
I have a plain Java application that runs JUnit tests programmatically, using OpenTestReportGeneratingListener to create an event-based Open Test Report. I have the following code that that will run JUnit tests programmatically from a Quarkus application (outline only for clarity): LauncherConfig config = LauncherConfig.builder()... .build();
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectClass(QuarkusBridge.class)... .build();
LauncherFactory.create(config).execute(request, new OpenTestReportGeneratingListener());
// QuarkusBridge.java
@TestFactory
public Collection<DynamicTest> dynamicTestsWithCollection(TestReporter reporter, TestInfo testInfo) {
return Arc.container().instance(TestCoordinator.class).get().computeTests(reporter, testInfo);
}
public Collection<DynamicTest> computeTests(TestReporter reporter, TestInfo testInfo) {
// create a list of DynamicTest objects that contain the test logic
} I am using the OTR-CLI to create a HTML report. I have read that it is possible to extend the HTML report and I have checked out the example from JUnit implementation of a Contributor. What I want now is to extend the HTML report so that for each executed test a link is displayed. The link will be used to download assets that were created during test execution. Is this possible? What steps are needed to add this data to the OTR reports so that it can be included in the HTML report? I am new to OTR and have used primarily to write "traditional" unit/integration tests so far (surefire reports that are rendered in Jenkins). Unfortunately the OTR docs and example code have not given me enough information and I haven't found any additional documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Extending the HTML report requires information to be present in the OTR XML files that are used as inputs. Since you're using In the meantime, I recommend using report entries for this purpose. Assuming you're using JUnit Jupiter, you could do this directly from your test code or a custom extension. import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestReporter;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
public class ExampleTests {
@Test
void testThatReportsLink(TestReporter testReporter) {
testReporter.publishEntry("my-artifact", "link:https://example.org");
}
@Test
@ExtendWith(ExampleExtension.class)
void testUsingAnExtensionReportingALink() {
}
static class ExampleExtension implements AfterTestExecutionCallback {
@Override
public void afterTestExecution(ExtensionContext context) {
context.publishReportEntry("my-artifact", "link:https://example.org");
}
}
} The Important An alternative would be to attach these files to the test report directly using the brand-new feature that I added in #4138. It's not released yet, but feedback would be very welcome! |
Beta Was this translation helpful? Give feedback.
It ain't pretty but it works: