Request mappings missing if a test context is reused in a test setup with a common test base class
See original GitHub issueDescribe the bug
We use WireMock to stub responses for HTTP requests to external systems. To reduce boilerplate code in our test classes, we introduced a test base class that handles general test setup for Spring Boot and WireMock. The test classes may run in different test contexts (e.g. differing active profiles) that are shared across the test classes (no DirtiesContext used).
This setup worked fine so far. However, some tests fail when switching from version 2.2.2.RELEASE (via HOXTON.SR4) to version 2.2.3.RELEASE ( via HOXTON.SR5). It turned out that all tests of test classes fail, which run in a text context that was already used by a previous test class. The failure reason is that no request mapping was found, although the respective stubs were set up in the tests.
Potential reasons for this new behavior are changes that were made to WireMockTestExecutionListener
and WireMockConfiguration
in this commit. Unfortunatelly, I could not yet exactly figure out what the root cause is.
Sample
see my demo project on GitHub.
The tests in this project use a TestRestTemplate to send HTTP requests. A WireMock stub is used to simulate the response. To “simulate” different test contexts, the test classes are annotated with different active profiles. There are two different setups. In the root package, the test classes contain the entire test setup. In the subpackage inheritance, a base class is used to reduce code duplication / simplify the test setup.
If all tests in package com.example.demo
are run, the tests pass. If all tests in package com.example.demo.inheritance
are run, the test ZTest fails (“no request mapping was found”).
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
I have the same problem: https://stackoverflow.com/questions/64063372/multiple-application-contexts-in-spring-junit-test-with-wiremock
@marcingrzejszczak Looks like you already resolved the problem - cool! I guess you don’t need the logs anymore? I’ld delete them from the comments to make the issue a bit more compact…