-
Notifications
You must be signed in to change notification settings - Fork 31
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
WeldInitiator does not call @PostConstruct methods #229
Comments
Hello and thanks for the report @jetztgradnet. Why do you need to perform post construct on the test object?
Note that the test instance is not a managed bean and as such does not follow this contract. It is in fact provided by JUnit (which also controls its lifecycle) and we just inject into it for convenience. |
Thanks for the quick response! |
This should be guaranteed by the JUnit specification. Extensions (
I will close it; given current setup, invoking FTR, the reason why JUnit provides the instance and not Weld is mostly historical as in early days of JUnit this wasn't possible and later on it was a breaking change to rewrite it. |
Thanks for your time and helping me with the explanation! Greatly appreciated. |
When injecting targets (beans, test classes, ...) in JUnit5 tests with
WeldJunit5Extension
, methods annotated with@jakarta.annotation.PostConstruct
are not executed, which does not fulfil the contract described by Weld (see https://docs.jboss.org/weld/reference/5.1.4.Final/en-US/html_single/#_injecting_java_ee_resources_into_a_bean).Essentially,
AbstractWeldInitiator.ToInject#inject()
is missing a call toinjectionTarget.postConstruct(instance);
after performing the injection.See https://github.com/weld/weld-testing/blob/master/junit-common/src/main/java/org/jboss/weld/junit/AbstractWeldInitiator.java#L328 for the respective code.
Example with pseudo code:
For now I use
@Inject
instead of@PostConstruct
as a workaround, but that only works, because all my other injections are for fields which are guaranteed to be set before calling methods.I used Weld
5.1.4.Final
andweld-testing
4.0.3.Final
.The text was updated successfully, but these errors were encountered: