You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're doing some setup work in our @BeforeAll method and inject various parameters to the lifecycle method that get resolved by other JUnit Jupiter extensions. However, our test fail because when it's the turn of the PactConsumerTestExt to determine if this extension is responsible for resolving the parameter, it expects a test method to be present in the context. That's not the case as no method has been selected yet as we're in the @BeforeAll lifecylce.
I tested it with JUnit 5.9.0 and au.com.dius.pact.consumer 4.4.2 and get the following exception:
org.junit.jupiter.api.extension.ParameterResolutionException: Failed to resolve parameter [java.lang.String arg0] in method [static void de.rieckpil.blog.SamplePactTest.setup(java.lang.String)]: Illegal state: required test method is not present in the current ExtensionContext
at org.junit.jupiter.engine.execution.ParameterResolutionUtils.resolveParameter(ParameterResolutionUtils.java:159)
at org.junit.jupiter.engine.execution.ParameterResolutionUtils.resolveParameters(ParameterResolutionUtils.java:103)
// ...
Caused by: org.junit.platform.commons.PreconditionViolationException: Illegal state: required test method is not present in the current ExtensionContext
at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:299)
at org.junit.platform.commons.util.Preconditions.notNull(Preconditions.java:55)
at org.junit.jupiter.api.extension.ExtensionContext.getRequiredTestMethod(ExtensionContext.java:241)
at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.lookupProviderInfo(PactConsumerTestExt.kt:271)
at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.supportsParameter(PactConsumerTestExt.kt:57)
at org.junit.jupiter.engine.execution.ParameterResolutionUtils.lambda$resolveParameter$0(ParameterResolutionUtils.java:114)
// ...
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at org.junit.jupiter.engine.execution.ParameterResolutionUtils.resolveParameter(ParameterResolutionUtils.java:115)
A minimal test example looks like the following:
@ExtendWith({PactConsumerTestExt.class, MyStringResolverExtension.class})
@PactTestFor(providerName = "some-provider", providerType = ProviderType.ASYNCH)
classSamplePactTest {
@BeforeAll// when evaluating whether or not the PactConsumerTestExt is responsible for this parameter, the extension failsstaticvoidsetup(StringinjectedString) {
System.out.println(injectedString);
}
@Pact(consumer = "some-consumer")
publicMessagePactsomeMessage(MessagePactBuilderbuilder) {
returnbuilder.withContent(LambdaDsl.newJsonBody(object -> object.stringType("test", "Test")).build()).toPact();
}
@Test@PactTestFor(pactMethod = "someMessage")
voidconsume(List<Message> messages) {
System.out.println(messages);
}
}
I assume that there's no context.requiredTestMethod present at this time of the lifecycle as the JUnit Jupiter lifecycle method is called before any test method.
fun lookupProviderInfo(context: ExtensionContext): List<Pair<ProviderInfo, String>> {
logger.trace { "lookupProviderInfo($context)" }
val store = context.getStore(NAMESPACE)
val providerInfo = when {
store["providers"] != null -> store["providers"] as List<Pair<ProviderInfo, String>>
else -> {
val methodAnnotation = if (AnnotationSupport.isAnnotated(context.requiredTestMethod, PactTestFor::class.java)) {
We tried to explicitly order the extension but even though an extension reports it's responsible for resolving a parameter, still all other extensions in the chain are asked if they support the parameter.
A current workaround is to use @BeforeEach where it works as there's already a selected test method. However, that's not suitable as we want our test setup work to be done only once for a test.
The text was updated successfully, but these errors were encountered:
Hey 👋🏻,
We're doing some setup work in our
@BeforeAll
method and inject various parameters to the lifecycle method that get resolved by other JUnit Jupiter extensions. However, our test fail because when it's the turn of thePactConsumerTestExt
to determine if this extension is responsible for resolving the parameter, it expects a test method to be present in the context. That's not the case as no method has been selected yet as we're in the@BeforeAll
lifecylce.I tested it with JUnit 5.9.0 and
au.com.dius.pact.consumer
4.4.2 and get the following exception:A minimal test example looks like the following:
I assume that there's no
context.requiredTestMethod
present at this time of the lifecycle as the JUnit Jupiter lifecycle method is called before any test method.I created a minimal reproducible example here.
We tried to explicitly order the extension but even though an extension reports it's responsible for resolving a parameter, still all other extensions in the chain are asked if they support the parameter.
A current workaround is to use
@BeforeEach
where it works as there's already a selected test method. However, that's not suitable as we want our test setup work to be done only once for a test.The text was updated successfully, but these errors were encountered: