Introducing the most powerful stateful mocking ever
![](https://cdn.prod.website-files.com/638f84bf34cdb1a901813e42/669ef72cc4102454c9b34ac5_stateful-mocking.jpg)
For all the benefits that API mocking provides, the gap that remains in many people’s minds is the distance between mocks, which are often fairly simple and the complexity of production services. WireMock Cloud has been chipping away at this problem for some time, with dynamic response, chaos testing, scenarios, data imports, dynamic matching and more – and now we are introducing the most robust stateful mocking system on the market.
With WireMock’s new stateful mocking capabilities, you can easily reproduce even the most complex real world interactions, making your API mock server indistinguishable from production services and raises the bar for your testing, quality assurance and velocity.
What is stateful mocking?
WireMock Cloud’s stateful mocking allows you to create and manage stateful journeys within your mock APIs. This means you can simulate scenarios where data changes over time, such as user account balances or shopping basket contents, without the complexities traditionally associated with trying to accomplish this - such as having to build custom simulators, bespoke stateful logic or sandbox business rules. This feature supports multiple users running stateful tests simultaneously, each in their isolated contexts, ensuring no cross-interference.
With native helpers, scopable contexts and the ability to integrate webhooks and more, stateful mocking in WireMock Cloud finally solves the problem of reproducing complex real world interactions without needing to take on a huge amount of complexity in return.
What can you use it for?
The possibilities for stateful mocking are endless, and we touch on some in our recently published WireMock Cloud academy video on the topic. But, here are a few ideas -
- Testing Stateful APIs: Stateful mocking is perfect for simulating CRUD operations, where data creation, reading, updating, and deletion need to be tested in a controlled environment. Whether you're testing a banking application where account balances change or an e-commerce platform tracking order statuses, stateful mocking makes it easier to mimic real-world API behavior.
- Concurrent User Testing: In scenarios where multiple users interact with your system simultaneously, stateful mocking ensures that each user's interactions are isolated. This is crucial for applications with high concurrency requirements, such as social media platforms or collaborative tools, allowing for accurate and realistic testing.
- Dynamic Response Generation: With stateful mocking, you can generate responses based on real-time request data. For instance, an API endpoint can return and update different user profile attributes based on the state information provided in the request, making it invaluable for testing personalized user experiences.
![](https://cdn.prod.website-files.com/638f84bf34cdb1a901813e42/669ef5aba5d1d6c4739b93b1_AD_4nXdtqAfuJljxwK_AhWoPtVjNFYWLSlOibBrv6Gt8dl4hcMFY2bY9CsLUlIbwwKC-BGkOt3UKIvK8nwcEPH1JRVxFDLwo7RYyq6QqGDbcZdCzZvi5XY7bU5KmPZT-ojVFlNPUL6EdVUw3503AjfFt6S_pnJhL.png)
How do you use it?
For a full overview, check out the documentation or the WireMock Cloud academy video – but getting started couldn’t be easier.
![](https://cdn.prod.website-files.com/638f84bf34cdb1a901813e42/669ef5e329ec11d74347caef_AD_4nXc6iNJK04sI-qS0GlutqUD7DABvY3UU3ql7MBdsTEEBZGW6QOO2t2ZAlt78rkpGGpI7UW28KX6kiiWAetfCWBCym5VP6AYmoU7kdNzgfxX76c8WJohFRX8MyzJ-G7ictyP8B5kQNS1xXXUCvkPMOXa2D11K.png)
- Enable dynamic states: Start by defining the state variables relevant to your scenario. For example, user balances, session tokens, or order statuses.
- Set Contexts: Use contexts to isolate state variables the appropriate scope, which would be a user session, a short-lived workflow, or a resource such as a payment. . Each context can have its own set of state variables, ensuring no overlap between different resources or concurrent sessions.
- Mock Responses: Configure your mock endpoints to use the state variables in generating responses. This allows the responses to reflect the current state accurately, providing a realistic simulation of your API’s behavior.
Mocking is more realistic than ever
The introduction of stateful mocking in WireMock Cloud represents a significant leap forward in API mocking capabilities. By allowing for precise control over stateful data and enabling concurrent, isolated user sessions, it addresses many of the challenges faced in modern API testing.
- Mocking reality: Simulate real-world scenarios accurately, leading to more reliable and accurate test results which means higher quality software with fewer production issues
- Less overhead: You can get rid of complicated test environments that are expensive, hard to maintain and typically out of date.
- Developer efficiency: Replace the complexity of setting up and managing bespoke tests that need to be meticulously crafted to try to capture real world behaviour with a simple stateful mocking configuration
- Org-wide testing impact: Entire teams can rely on mock servers in parallel to test different states and different data interactions with no risk of conflict or collision.
- Better demos: Stateful mocking can bring feature demos to life when showing joined-up workflows.
For more information check out the documentation or get in touch!
/