Running Tests In Parallel
To ensure all tests can run in parallel with completely isolated independent data it is important to include a value unique to each test for the request matcher.
If each test generates a unique value (i.e. a UUID) for the sessionId cookie or a correlationId header then each test can receive completely independent response.
Java
String sessionId = UUID.randomUUID().toString();
new MockServerClient("127.0.0.1", 1080)
.when(
request()
.withMethod("GET")
.withPath("/somePath")
.withCookies(
cookie("sessionId", sessionId)
)
)
.respond(
response()
.withStatusCode(200)
.withBody("{ name: 'value' }")
);
JavaScript
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
var sessionId = guid();
mockServerClient("localhost", 1080)
.mockAnyResponse({
'httpRequest': {
'method': 'GET',
'path': '/somePath',
"cookies": {
"sessionId": sessionId
}
},
'httpResponse': {
'statusCode': 200,
'body': JSON.stringify({name: 'value'})
}
})
.then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);