Ensure parallel execution of tests and mocking

See original GitHub issue

Hello,

I like the kind of WireMock for stubbing and testing. Nice work! Much better than starting the old sun lib HttpServer 😉

I’m currently using WireMock for mocking service calls and testing http clients. As test suite I take TestNG. The test suite can be executed parallel and several client tests are running at the same time. Each test instantiates a WireMock server and ends it after the test class is done.

The problem is, that the static instance of WireMock is not suitable for multiple threads.

private static WireMock defaultInstance = new WireMock();

To solve this problem I suggest to add another method on instance level, like this:

WireMock wm =  WireMock.createInstance(); 
wm.stubFor();
wm.verify();

Alternatively, the ‘stubFor()’ and ‘verify()’ methods take their instance from a ThreadLocal variable.

What do you think about the suggestions?

Thanks Olli

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:5
  • Comments:14

github_iconTop GitHub Comments

1reaction
jamietannacommented, Jan 27, 2022

Hey @swtestacademy mind raising a separate issue for us to discuss that in? 🙏

0reactions
swtestacademycommented, Jan 14, 2022

Hi all,

Is there any way to create a new wiremock instance when we are using @AutoConfigureWiremock annotation?

I solved the dynamic port issue but when I am using @AutoConfigureWireMock annotation with JUnit 5, I could not create multiple instances and tests are failing in parallel execution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ensure parallel execution of tests and mocking #169 - GitHub
I'm currently using WireMock for mocking service calls and testing http clients. As test suite I take TestNG. The test suite can be...
Read more >
Running Tests In Parallel - MockServer
To ensure all tests can run in parallel with completely isolated independent data use a unique value for each test. The unique value...
Read more >
C# Mocking Framework With Parallel Support - Stack Overflow
How to setup Parallel Test Execution in Visual Studio 2010: This link outlines the mechanism to enable parallel test execution.
Read more >
Concurrent Test Execution in Spring 5 - Baeldung
Starting with JUnit 4, tests can be run in parallel to gain speed for larger suites. The problem was concurrent test execution was...
Read more >
Testing in parallel with Mocha v8.0.0 - IBM Developer
Running tests in parallel mode allows Mocha to take advantage of multi-core CPUs, resulting in significant speedups for large test suites. Read ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found