Skip to content

fix: inject @InjectWireMock fields without explicit SpringExtension - #213

Merged
tomasbjerre merged 1 commit into
mainfrom
fix/212-inject-wiremock-without-spring-extension
Oct 5, 2026
Merged

tomasbjerre merged 1 commit into
mainfrom
fix/212-inject-wiremock-without-spring-extension

Conversation

@tomasbjerre

Copy link
Copy Markdown
Collaborator

Summary

  • @ConfigureWireMock/@EnableWireMock only meta-annotated @ExtendWith(WireMockSpringJunitExtension.class), which feat: support test engines other than JUnit Jupiter #204 turned into a pure ParameterResolver. Field injection, resets and the default WireMock client now run from WireMockTestExecutionListener, which only fires when Spring's SpringExtension is registered — previously that happened implicitly as a side effect of SpringExtension.getApplicationContext() being called during field lookup.
  • Test classes without @SpringBootTest, @SpringJUnitConfig or an explicit @ExtendWith(SpringExtension.class) therefore got null @InjectWireMock fields (4.4.0+ regression, fixes [Bug]: @InjectWireMock fields are no longer injected in tests without SpringExtension` #212).
  • Fix: also meta-annotate @ConfigureWireMock/@EnableWireMock with @ExtendWith(SpringExtension.class). @ExtendWith is @Repeatable, so this stacks cleanly with whatever a test class already registers and doesn't affect the Cucumber/TestNG path added in feat: support test engines other than JUnit Jupiter #204 (those don't go through JUnit 5 meta-annotation extension discovery).

Test plan

  • Added InjectWireMockWithoutExplicitSpringExtensionTest, reproducing the issue's exact repro case (only @ConfigureWireMock + @InjectWireMock, no @SpringBootTest/@SpringJUnitConfig/explicit SpringExtension).
  • Confirmed this test fails (null field) on the code before this fix, and passes with it.
  • ./gradlew test passes in full with no regressions.

🤖 Generated with Claude Code

@ConfigureWireMock and @EnableWireMock only meta-annotated @ExtendWith
with WireMockSpringJunitExtension, which became a pure ParameterResolver
in #204. Field injection, resets and the default WireMock client now run
from a Spring TestExecutionListener, which only fires when SpringExtension
is registered - previously an implicit side effect of
SpringExtension.getApplicationContext() being called during field lookup.
Test classes without @SpringBootTest, @SpringJUnitConfig or an explicit
@ExtendWith(SpringExtension.class) got null @InjectWireMock fields.

Meta-annotate both annotations with an additional
@ExtendWith(SpringExtension.class); @ExtendWith is @repeatable so this
stacks cleanly with whatever a test class already registers.

Fixes #212

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tomasbjerre tomasbjerre added the enhancement New feature or request label Oct 5, 2026
@tomasbjerre
tomasbjerre merged commit d3eef6a into main Oct 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @InjectWireMock fields are no longer injected in tests without SpringExtension`

1 participant