🐞: No execution info when running tests via JUnit5 Launcher API
What happened?
I run tests this way, but the results show an incomplete report, there is no data with annotations @Step and @Attachment
private static void executeTest(String testIdentifier) {
LauncherDiscoveryRequest request;
if (testIdentifier.contains("#")) {
request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectMethod(testIdentifier))
.build();
} else {
request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectClass(testIdentifier))
.build();
}
System.setProperty("allure.results.directory", "target/test-result/allure-results");
System.setProperty("junit.jupiter.extensions.autodetection.enabled", "true");
LauncherConfig launcherConfig = LauncherConfig.builder()
.enableTestExecutionListenerAutoRegistration(true)
.build();
SummaryGeneratingListener summaryGeneratingListener = new SummaryGeneratingListener();
try (LauncherSession session = LauncherFactory.openSession(launcherConfig)) {
Launcher launcher = session.getLauncher();
launcher.registerTestExecutionListeners(summaryGeneratingListener);
TestPlan testPlan = launcher.discover(request);
launcher.execute(testPlan);
}
}
Can this be fixed?
What Allure Integration are you using?
allure-junit5
What version of Allure Integration you are using?
2.29.0
What version of Allure Report you are using?
2.29.0
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
This is not a bug, but a logical behavior, since allure-java uses aspectj javaagent to work with @Step and @Attachment annotations.
If you look at the documentation in the settings section, you will see that aspectj is called on the command line when you run the surefire plugin - https://allurereport.org/docs/junit5/#configure-aspectj
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" which your runner is missing.
In my opinion, you have 3 options:
- Use manually written
Allure.step("Step Name", () -> {})andAllure.addAttachment("name", "value"), which are not requiresaspectj
- https://allurereport.org/docs/steps/#step-parameters
- https://allurereport.org/docs/steps/#step-attachments
- Add
-javaagentto jvm parameters as described inaspectjconfiguration inmaven-surefire-plugin, however theaspectjweaver-version.jaritself must be present in the file system, or there must be any maven/gradle/any package manager that will downloadaspectjbefore your call to the Main class But anyway - https://allurereport.org/docs/junit5/#configure-aspectj - I can't recommend this solution because it will cause a lot of problems in the future, but atm you can load javaagent dynamically with
byte-buddy-agentbefore your runner code:
ByteBuddyAgent.attach(
new File("/path/to/aspectjweaver-version.jar"),
ManagementFactory.getRuntimeMXBean().getName().split("@")[0],
"-Daj.weaving.verbose=true"
);