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

Methods/constructors invoked via ExecutableInvoker should have access to current ExtensionContext and ExtensionRegistry #3905

Closed
marcphilipp opened this issue Jul 30, 2024 Discussed in #3896 · 0 comments · Fixed by #3906

Comments

@marcphilipp
Copy link
Member

Discussed in #3896

Originally posted by alanwong-toast July 22, 2024
I was hoping that ExecutableInvoker (accessible from ExtensionContext) would allow for the invocation of methods/classes with the currently known set of ParameterResolvers, but based on my testing, it seems that it only loads with a default set of resolvers and never the resolvers I have injected.

The creation of the DefaultExecutableInvoker happens here:

public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
MutableExtensionRegistry registry = populateNewExtensionRegistryFromExtendWithAnnotation(
context.getExtensionRegistry(), this.testClass);

ThrowableCollector throwableCollector = createThrowableCollector();
ExecutableInvoker executableInvoker = new DefaultExecutableInvoker(context);
ClassExtensionContext extensionContext = new ClassExtensionContext(context.getExtensionContext(),
context.getExecutionListener(), this, this.lifecycle, context.getConfiguration(), throwableCollector,
executableInvoker);
// @formatter:off
return context.extend()
.withTestInstancesProvider(testInstancesProvider(context, extensionContext))
.withExtensionRegistry(registry)
.withExtensionContext(extensionContext)
.withThrowableCollector(throwableCollector)
.build();
// @formatter:on

With this constructor for DefaultExecutableInvoker:

public DefaultExecutableInvoker(JupiterEngineExecutionContext context) {
this(context.getExtensionContext(), context.getExtensionRegistry());
}

It appears that the new extension registry generated from populateNewExtensionRegistryFromExtendWithAnnotation at the top is never passed into the new context that is used to construct the class's context.

This results in a default set of resolvers in all cases, regardless of which extension interface I use to get the extension context.

Is there a correct way to utilize ExecutableInvoker such that the context of the currently running test has access to that test's ParameterResolvers?

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

Successfully merging a pull request may close this issue.

1 participant