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
TestInstancePostProcessor
cannot be registered via @ExtendWith
on a non-static field
#3437
Comments
Should I be able to inject a Example: class BasicTests {
@ExtendWith(ExtensionInjector.class)
ExtensionInjector injector;
@RegisterExtension
ParameterResolver extension;
// some tests...
} Also: can I work on this issue? Other than this one question, I think I can handle it. |
Hi @Michael1993,
Ideally, yes, I believe so. At least, generally speaking a I believe I demonstrated that once with Spring. Let me see if I can find it... |
|
Thanks for volunteering! However, this issue is assigned to me and not labeled as In addition, it may turn out to be more challenging than you expect. In light of that, I would like to keep this assigned to me. FWIW, I took a glance at your spike, and I'd like to point out that we have no plans to add specific handling for a particular extension API (such as |
Sorry, I don't know how I missed that. I will take a look at the up-for-grabs issues instead, then. 🙂 |
Overview
As discovered by @graydavid in #3433, there is an issue regarding extension registration via
@ExtendWith
on instance fields.The following is a simplification of the
RandomNumberDemo
from the User Guide which demonstrates the problem.The above test fails; however, if you annotate the test class with
@ExtendWith(RandomNumberExtension.class)
the test then passes.The reason is that
ClassBasedTestDescriptor#instantiateAndPostProcessTestInstance()
invokesExtensionUtils.registerExtensionsFromFields()
too late.I even added the following comment when I introduced that support.
In retrospect, that is not the "best time to do that" when a field is annotated (or meta-annotated in the case of
@Random
) with an@ExtendWith
annotation that registers an extension that implementsTestInstancePostProcessor
.Related Issues
RandomNumberExtension
in the User Guide #3433RandomNumberExtension
in the User Guide #3463Deliverables
ExtensionUtils.registerExtensionsFromFields()
so that aTestInstancePostProcessor
can be registered via@ExtendWith
on a non-static field.The text was updated successfully, but these errors were encountered: