Mockserver offer the following advice for running tests in parallel
it is recommended to either use a unique instance of MockServer per test or to run tests in series and clear all expectations prior to each test. mockserver documentation on parallel usage
Running in parallel
Therefore I have created a unique instance of mockserver per test. The tests are run in parallel using SpringBoot and we use no tracking_ids or cookies since each test as its own mockserver instance.
The Problem
However, I have to create a new application context before running each test, because I need to store the random mockserver port, otherwise when the tests make eternal api calls, which need to be mocked, they wouldn't know which port to use in the mockserver base URL.
Example
Test 1: mockserver instance port 1445 (running in parallel)
Test 2: mockserver instance port 1446 (running in parallel)
Imagine both tests need to mock and endpoint like
www.google.com/test
Then test 1 will need to hit
www.mockerserver.com:1445/test
And test 2 will need to hit
www.mockerserver.com:1446/test
The only way this might work is by starting the application context before each test and updating all your mockable base URLs in your config using the newly generate mockserver port. But this is so slow it defeats the point of going parallel completely.
Why bad advice in documentation?
Why would mockserver documentation give this advice when it leads down this bad path?