Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micronaut is unable to inject dependencies into nested tests when using KSP #10941

Open
cainecridland opened this issue Jul 3, 2024 · 1 comment

Comments

@cainecridland
Copy link

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:

  1. Create a test class that uses the @MicronautTest annotation
  2. Create a nested inner class (with the @nested annotation) containing dependencies injected using the @Inject annotation
  3. Create a test within the inner class that uses the injected dependencies.
  4. The test will fail, but will pass if you move everything outside of the nested inner class.

Environment Information

  • Kotlin 2.0
  • JDK 17

Example Application

https://github.com/cainecridland/micronaut-nested-test-injection-problem-example

Version

4.4.0

@nilols
Copy link

nilols commented Aug 12, 2024

A workaround seems to be constructor-based injection

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants