I want to develop a stand-alone test-solution delivered as a jar
that can be used in a CI/CD environment without being recompiled all the time. Therefore I packed a fat-jar from a multi-maven-module containing a few libaries, a Spring Boot application and a submodule called test-runner
.
Executing the fat-jar from within GitLab CI/CD works, but I think that was only the first half of it. I want to produce a JUnit XML report to output the test-results. What I understood from my research is that I would have to implement my own reporter. Is there a more complete example out there?
The test runner
public class Runner {
SummaryGeneratingListener listener = new SummaryGeneratingListener();
public void runOne() {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectClass(MyTest.class)).build();
Launcher launcher = LauncherFactory.create();
TestPlan testPlan = launcher.discover(request);
launcher.registerTestExecutionListeners(listener);
launcher.execute(testPlan);
}
public static void resultReport(Result result) {
System.out.println("Finished. Result: Failures: " + result.getFailureCount() + ". Ignored: "
+ result.getIgnoreCount() + ". Tests run: " + result.getRunCount() + ". Time: "
+ result.getRunTime() + "ms.");
}
public static void main(String[] args) {
Runner runner = new Runner();
runner.runOne();
TestExecutionSummary summary = runner.listener.getSummary();
summary.printTo(new PrintWriter(System.out));
}
}
Background:
My test-solution is generic and uses a configuration file to parameterize the tests. All tests run in parallel versus a system-under-test. So before this attempt all gitlab-jobs called mvn test
to execute the tests and generate the reports, but it recompiled everything every run. I thought about speeding things up.
You can use Console launcher to geneate Junit5 xml reports
junitArgs.txt file has following info: