2

I am currently running a single test case with wire mock. Following is the code snippet:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = DEFINED_PORT)
public class ResolveIT {

 @ClassRule
 public static WireMockRule wireMockRule = new WireMockRule(8900);

 @Autowired
 private TestRestTemplate restTemplate;

 @BeforeClass
 public static void init() {
 wireMockRule.resetAll();
 }

 @Test
 public void testA() {

 HttpEntity<String> entity = new HttpEntity<String>(null, getRequestHeaders());
 ResponseEntity<String> response = restTemplate.exchange(localhost:8080/abc, HttpMethod.GET, entity, String.class);
 assertEquals(response.getStatusCode(), HttpStatus.OK);
 assertEquals(response.getBody(), "Hey");
 }
}

I have placed my stubs in a json file in mappings folder which looks like this:

{
 "request": {
 "method": "GET",
 "url": "/abc/xyz"
 },
 "response": {
 "status": 200,
 "bodyFileName": "body.json",
 "headers": {
 "Content-Type": "application/text",
 }
 }
}

I run this class as JUnit tests from my IDE. Now I need help with the following scenario:

I wish to run a test suite where multiple classes having such tests will run in parallel, in short, I wish to run wiremock tests in parallel. If I configure all my classes like this, I will have to provide a different port to make them run in parallel which doesnt seems to be a feasible solution here. Also I read somewhere that wiremock is not thread safe.

  1. How can I make the run thread safe?
  2. How can I configure my code so that wiremock runs on one port and all my tests can run in parallel? What should be code for that and how should that single instance of wiremock be configured and how the test should be run?
  3. To achieve this do I need to make the stubbing manually in each test class or can it be achieved along with dynamic stubbing through json file? P.S. - I am using maven in my project if it is required to be known.

0 Answers0