-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Cannot use @Inject and @TestInstance(TestInstance.Lifecycle.PER_CLASS) #1828
Comments
I wonder if it would be better to do the dependency injection implementing a JUnit https://junit.org/junit5/docs/current/user-guide/#extensions-test-instance-post-processing |
Hmm, Maybe it would make sense to instead move the Quarkus boot to I'll dig into this and see if I am right or wrong :) |
Having Quarkus booted only once is a design decision as far as I understand (we only want to do it once since it contains the entire augmentation phase which is something we don't want running multiple times). |
@geoand yeah I understood as much. |
@manovotn awesome! |
Quarkus testing brokes when you mark a
@QuarkusTest
with@TestInstance(TestInstance.Lifecycle.PER_CLASS)
and the test has an@Inject
fieldhttps://junit.org/junit5/docs/current/user-guide/#writing-tests-test-instance-lifecycle
This happens because Quarkus is bootstrapped in a
@BeforeAll
hookquarkus/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java
Lines 80 to 105 in ee8e68d
And JUnit's behavior is to instantiate the Test class before calling the
@BeforeAll
hook.The class instantiation is done in:
https://github.com/quarkusio/quarkus/blob/master/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java#L297-L309
and it tries to inject the dependencies but the ArC Container has not been initialized yet (chicken or egg problem)
I have a reproducer in https://github.com/cristhiank/quarkus-bugs
The text was updated successfully, but these errors were encountered: