If a @MicronautTest test and its injected dependencies are within a nested class, the dependencies are injected when the test in the nested class runs.
Actual Behaviour
The dependencies are not injected, leading to the following error: kotlin.UninitializedPropertyAccessException: lateinit property has not been initialized
Steps To Reproduce
Reproduction steps are available in the README of the example application below, but generally:
Create a test class that uses the @MicronautTest annotation
Create a nested inner class (with the @Nested annotation) containing dependencies injected using the @Inject annotation
Create a test within the inner class that uses the injected dependencies.
The test will fail, but will pass if you move everything outside of the nested inner class.
Expected Behavior
If a @MicronautTest test and its injected dependencies are within a nested class, the dependencies are injected when the test in the nested class runs.
Actual Behaviour
The dependencies are not injected, leading to the following error:
kotlin.UninitializedPropertyAccessException: lateinit property has not been initialized
Steps To Reproduce
Reproduction steps are available in the README of the example application below, but generally:
Environment Information
Example Application
https://github.com/cainecridland/micronaut-nested-test-injection-problem-example
Version
4.4.0