native-build-tools
native-build-tools copied to clipboard
JUnit 5 native tests fail with NoSuchElementException: No value present
I have been enabling native testing on the micronaut-test
project suite and the tests fails with:
Failures (1):
JUnit Jupiter
=> org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to execute tests
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:113)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
[...]
Caused by: org.junit.platform.commons.JUnitException: Error executing tests for engine junit-jupiter
org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:57)
org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
[...]
Caused by: java.util.NoSuchElementException: No value present
java.util.Optional.get(Optional.java:143)
org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations(AnnotationUtils.java:354)
org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations(AnnotationUtils.java:320)
org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations(AnnotationUtils.java:364)
org.junit.platform.commons.util.AnnotationUtils.findRepeatableAnnotations(AnnotationUtils.java:320)
[...]
Is this is a known issue?
Seems reflection is being used in AnnotationUtil
:
Method method = ReflectionUtils.tryToGetMethod(candidateAnnotationType, "value").toOptional().get();
@sbrannen do all JUnit 5 annotations need registering for reflection?
Full trace https://github.com/micronaut-projects/micronaut-test/runs/4369136089?check_suite_focus=true
Worked around with https://github.com/micronaut-projects/micronaut-test/pull/490/commits/db88c001be7b5a70e4f7382968e6e11ab3a2c191
@sbrannen do all JUnit 5 annotations need registering for reflection?
The annotation search algorithms in JUnit 5 do indeed use a lot of reflection in order to support meta-annotations.
Thus, any repeatable annotation (such as the @Property
one from Micronaut) will need to be opened up for reflection if such annotations are present on methods, constructors, fields, etc. in test classes or test interfaces.
Even if such annotations are not actually used in the tests, JUnit will still use reflection to introspect them.
Did you have to add reflection configuration for java.lang.annotation.Retention
and java.lang.annotation.Target
because of JUnit?
If so, that seems like a bug to me, and I'd like to fix that in JUnit if necessary.
Even if such annotations are not actually used in the tests, JUnit will still use reflection to introspect them.
In light of that fact, we could probably make the UX better by automatically registering such annotations for reflection.
We already do quite a bit in the config package for the Feature.
@graemerocher, is this still relevant on recent versions of GraalVM?
I haven't tested without our workaround in place to be honest, will need to try
@graemerocher, is this still relevant on recent versions of GraalVM?
Ping!
can't reproduce anymore so closing. Thanks.