MockWebServer: Clear requests before each test
See original GitHub issueCan we have a method to clear requests? Something like this:
@BeforeEach
fun cleanRequests() {
mockServer.clearRequests();
}
My tests are taking requests from previous tests. I wouldn’t want to shutdown entirely
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Running test with MockWebServer always call the failure call ...
I'm running mock web server to test ...
Read more >Test Spring WebClient with MockWebServer from OkHttp
Write tests for your Spring WebClient usage with OkHttp's MockWebServer and mock HTTP responses to test different scenarios.
Read more >Clearing & Resetting - MockServer
Clearing & Resetting. MockServer has the following internal state: recorded requests; active expectations; recorded expectations; logs.
Read more >Integration Testing with MockWebServer - Industrial Logic
It creates a real WebClient, and inserts the randomly generated url from the mockServer into it. Then, before each test, you can insert...
Read more >MockWebServer.setDispatcher - Java - Tabnine
@Override protected void before() throws Throwable { clear(); server = new MockWebServer(); final Dispatcher dispatcher = new Dispatcher() { @Override ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
DynamicPropertyRegistry method must be static as per documentation, so I guess it does not reevaluate within the class. I think that would imply restarting the whole spring context since the mechanism is similar to that of @SpringBootTest(properties=X). So we’d need the mockrestserver instance to be static as well, I am not sure it makes sense to reinstantiate it globally and start/shutwoning on each test, I find the clearRequests() approach more comfy for that scenario
Is it possible the item reading the property is in the wrong scope? Singleton?
https://www.baeldung.com/spring-dynamicpropertysource