The getter for the hostName and port fields for the MockWebServer starts the server by calling the before().
This behaviour is misleading and it should throw an IllegalStateException instead.
Normally this would be an issue with breaking existing clients using this behaviour. We might have a small window to fix this ahead of next release when the mockwebserver3 split happens.
Unless there is a strong argument for visibly changing the behaviour, I'm going to close this out as it likely breaks way more tests and causing pain if we do fix it.
@yschimke Yeah, I agree it will cause more inconvenience if the behaviour is changed.
Everything should be fine as it is right now I guess. Perhaps a note can be written in the documentation of the methods that are calling the before() to state that they'll automatically start the server.
With OkHttp 5 and MockWebServer repackaging we might be able to fix this?
(though I鈥檓 unsure we want to!)
It seems like a toss up between. Correct but annoying, warns you for using it before you start. Or helpful but lenient.