question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request mappings missing if a test context is reused in a test setup with a common test base class

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
luddwichrcommented, Dec 9, 2020

@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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple Application Contexts in Spring JUnit test with WireMock
When the spring cached test contexts are reused the wiremock port changes back to that contexts port but seems to miss some step...
Read more >
Improve Build Times with Context Caching from Spring Test
If most of your tests share the same context configuration, you can reuse the Spring context for multiple tests and reduce the overall...
Read more >
Unit Testing of Spring MVC Controllers: Configuration
This blog post describes how we can configure our unit tests which use the Spring MVC Test framework.
Read more >
Shared Context between Tests > xUnit.net
This makes the constructor a convenient place to put reusable context setup code where you want to share the code without sharing object...
Read more >
Top 10 Most Common Spring Framework Mistakes - Toptal
In this article, we cover the most common pitfalls of using the Spring framework so new and experienced developers alike have a roadmap...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found