To ensure all tests can run in parallel with completely isolated independent data use a unique value for each test. The unique value for a test should be specified in each request matcher for all expectations for that test. This ensures that expectations created by one test are not visible by other tests and therefore keeps test isolated without needing multiple separate instances of MockServer.

For example, if each test generates a unique value (i.e. a UUID) for the sessionId cookie or a correlationId header then this header or cookie can be specified in each expectation's request matcher ensuring only requests with that unique value could be matched against expectations with that unique value.

Note: the drawback with this approach is that the logs will be more complex to understand because there will be a large number of expectation match failures, therefore 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.


String sessionId = UUID.randomUUID().toString();

new MockServerClient("", 1080)
                cookie("sessionId", sessionId)
            .withBody("{ name: 'value' }")


function guid() {
    function s4() {
        return Math.floor((1 + Math.random()) * 0x10000)
    return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
        s4() + '-' + s4() + s4() + s4();

var sessionId = guid();

mockServerClient("localhost", 1080)
        'httpRequest': {
            'method': 'GET',
            'path': '/somePath',
            "cookies": {
                "sessionId": sessionId
        'httpResponse': {
            'statusCode': 200,
            'body': JSON.stringify({name: 'value'})
        function () {
            console.log("expectation created");
        function (error) {