MockWebServer clearing all requests at once
I am using MockWebServer as a bean in Spring Boot Test. The problem I have is that not all test methods need to get the request sent, but when I get to the test method that needs to get request sent, it first gets requests sent in previously executed test methods. Maybe a method on MockWebServer that clears all requests could help in situations like this.
Currently a work-around I am using is a kotlin extension method that calls takeRequest() n times, where n = requestCount of MockWebServer.
Maybe the same functionality could be useful for enqueued responses to set default test context. For example, setting mock web server to enqueue a successful response and then, for other cases, clear the enqueued response(-s) and enqueue a different response.
Actually, just found out, my work-around does not work because I assumed requestCount returns a number of requests sent but not taken with takeRequest, but it returns the total number of requests sent including those sent and taken with takeRequest. Calling the time-based takeRequest should work.
Can you use different mock webserver instances?
See the description in https://github.com/square/okhttp/issues/6906#issuecomment-966858483
There is a deliberate design choice to make MockWebServer single use. If you look at MockWebServerRule (junit4) or MockWebServerExtension (junit5) you will see that is how they are implemented.
Closing as low priority, unlikely to get addressed.