micronaut-test
micronaut-test copied to clipboard
JUnit tests in Gradle project cannot be run from Eclipse
Expected Behavior
In a Gradle project, right clicking on a JUnit 5 test class annotated with @MicronautTestand selecting Run As -> JUnit Test should successfully run the tests inside the IDE.
Actual Behaviour
The JUnit engine fails to run the tests and the following error message is surfaced in Eclipse:
org.junit.jupiter.engine.execution.ConditionEvaluationException: Failed to evaluate condition [io.micronaut.test.extensions.junit5.MicronautJunit5Extension]: @MicronautTest used on test but no bean definition for the test present. This error indicates a misconfigured build or IDE. Please add the 'micronaut-inject-java' annotation processor to your test processor path (for Java this is the testAnnotationProcessor scope, for Kotlin kaptTest and for Groovy testCompile). See the documentation for reference: https://micronaut-projects.github.io/micronaut-test/latest/guide/
This seems to be a widespread issue, a quick search highlights other similar reports:
- https://stackoverflow.com/questions/61594792/how-can-i-test-a-micronaut-service-with-junit5
- https://stackoverflow.com/questions/62900897/micronaut-how-to-configure-micronaut-annotation-processors-for-junit-in-eclipse
- https://stackoverflow.com/questions/61562964/what-dependency-is-to-code-in-build-gradle-to-import-package-package-io-microna#comment111236280_61570064
- https://gitter.im/micronautfw/questions?at=5d289199f4fe943971f5a409
- https://github.com/micronaut-projects/micronaut-core/issues/714#issuecomment-659603734
Steps To Reproduce
- Download and install Eclipse IDE for Java Developers.
- Check out one of the examples: https://github.com/micronaut-projects/micronaut-examples/tree/master/hello-world-java
- Follow the official documentation to import the Gradle project into Eclipse: https://docs.micronaut.io/latest/guide/#eclipseSetup
- In the Package/Project explorer, navigate to
HelloControllerTest.java. - Right click on the class, select
Run As->JUnit Test.
Note that micronaut-examples uses an outdated version of Micronaut, but I'm able to reproduce with the latest one as well.
Environment Information
- macOS Big Sur 11.6.2
- OpenJDK 17 2021-09-14
- Eclipse 2021-12
Let me know if you need any additional information.
Example Application
https://github.com/micronaut-projects/micronaut-examples/tree/master/hello-world-java
Version
1.3.3