Acceptance Testing with Mokapi: Focus on What Matters
Marcel Lehmann

Marcel Lehmann @marcel_lehmann_31109127df

About: Founder of Mokapi – an open-source tool for mocking APIs like REST and Kafka using OpenAPI and AsyncAPI.

Location:
Switzerland
Joined:
May 3, 2025

Acceptance Testing with Mokapi: Focus on What Matters

Publish Date: Jul 8
1 0

In today’s fast-paced development cycles, it’s crucial to ensure your software meets real user expectations. While unit tests validate internal code, acceptance testing answers the bigger question: Does the system behave as users expect? This post explores the value of acceptance tests and how Mokapi supports it by simulating APIs, validating specifications, and enabling robust, realistic test cases.

Why Acceptance Testing

Software testing is not merely a box to check—it is a fundamental process to answer one critical question: Is our software releasable?

Among the various levels of testing, acceptance testing offers the most direct insight into whether the software meets business and user expectations. It bridges the gap between the world of users and the inner workings of the code by turning expectations into precise, executable checks on system behavior.

The Nature of Acceptance Tests

At its core, an acceptance test is an executable specification of how a system should behave, written from a user’s perspective. It is not concerned with how the system is implemented, but with what it does—its behavior and its outcomes.

While unit tests focus on individual components, acceptance tests focus on the system's intent. They clarify what should happen when a user interacts with the software under certain conditions.

When we get the level of abstraction right, acceptance tests become clear, precise, and maintainable. They reflect scenarios that matter to users, expressed in a way that is both easy to read and easy to execute. They serve as living documentation that evolves with the system and its requirements.

Solving Ambiguity and Ensuring Reproducibility

One of the most challenging aspects of software development is not writing code—it is understanding the problem clearly and expressing it precisely. Programs are, after all, specifications of what we want the system to do. But unlike natural languages, which are rich in context and ambiguity, software requires unambiguous clarity.

This is where acceptance testing shines.

By expressing requirements in an executable form, acceptance tests remove ambiguity. They define exactly what needs to happen. Rather than relying on vague documentation or human interpretation, developers, testers, and stakeholders can rely on concrete, shared understanding. The tests describe behavior, not implementation details, which makes them robust to changes in how the system is built, as long as it continues to behave as expected.

Moreover, acceptance tests are reproducible. They can be run automatically, as often as needed, to ensure the software continues to meet its defined expectations. This reproducibility is crucial for modern CI pipelines, where tests are run continuously to catch regressions early

A Contract of Trust

In a collaborative development environment, acceptance tests serve as a contract between the business and the development team. When everyone agrees on the specifications encoded in the tests, there is no room for misinterpretation. The business gets what it asked for, and developers have a reliable guide to follow.

This contract is especially important in agile and iterative processes, where requirements evolve and features are delivered incrementally. With acceptance tests in place, the team always has a clear picture of what "done" means.

Making Software Releasable

Acceptance testing answers a key question: Is the software ready to release? It gives us confidence that the features meet user needs and work correctly. It also checks that we built what was actually requested. Most importantly, it does this in a way that’s automated, repeatable, and reliable.

By aligning development with user intent, removing ambiguity, and validating results, acceptance testing becomes an essential practice—not just for verifying software, but for clearly understanding and specifying it in the first place.

The problem with acceptance testing and 3rd party APIs

Unstable – External APIs can fail randomly, whether due to bugs or release workflows.
No test environment – Many APIs don’t offer a dedicated environment for testing.
Uncontrollable state – It’s often impossible to set up the external system in the desired state for your tests.

These limitations can make acceptance testing brittle and unreliable—unless you can simulate the external system reliably.

How Mokapi Supports Acceptance Testing

That’s where Mokapi comes in. It lets you simulate realistic API behavior in a way that’s fast, accurate, and under your full control.

Acceptance testing becomes significantly more effective with the right tools—especially in complex environments with multiple APIs, microservices, and evolving interfaces. Mokapi was developed to address precisely these challenges. It provides a powerful, flexible, and specification-oriented approach to API simulation, enabling high-quality acceptance testing in a wide variety of scenarios.

Acceptance Testing Across Boundaries

Mokapi makes acceptance testing easier across flexible system boundaries—whether you're focusing on a single microservice or validating your entire architecture—by mocking the APIs they depend on.

Powerful Flexibility for Real-World Scenarios
With Mokapi, you're not limited to ideal cases. The JavaScript-based mock handlers enable the simulation of a wide variety of real-world scenarios, including negative tests, edge cases, and error conditions—all essential for developing robust software. You can programmatically control responses based on request data, headers, or business logic, giving you precise control over your mock's behavior during a test.

This flexibility helps you answer not only the question "Does it work?" but also "Does it work when third-party systems don't."

Specification-Driven Confidence

One of Mokapi's key strengths is its close alignment with API specifications. Mocks are continuously validated against OpenAPI or AsyncAPI definitions, ensuring they accurately reflect the APIs being simulated. This becomes especially valuable as APIs evolve.

When a provider releases a new API version, it can be easily updated in Mokapi. If mock data or API calls no longer conform to the updated specification, Mokapi returns errors that can be caught through acceptance testing. This supports automated API version updates and acts as an early warning system for potential production issues.

Smart Mock Customization with Patch Mechanism

Mokapi supports a patching mechanism for both API specifications and mock data. Patching the specification helps you adopt new API versions more easily while keeping track of your own modifications to the original spec. Patching mock data, on the other hand, allows you to avoid over-mocking—keeping your tests stable and focused, so changes are only required when they’re truly relevant.

Here's an example:

import { on, patch } from 'mokapi';
import { fake } from 'mokapi/faker';

export default function() {
    // Open the OpenAPI pet store specification, resolving all $ref references
    const api = open('pet-store-api.yaml', { as: 'resolved' });

    // Generate a random pet object based on the OpenAPI schema
    const pet = fake(api.components.schemas.pet);

    on('http', (request, response) => {
        // Use the generated pet but override the name to 'Odie'
        response.data = patch(pet, { name: 'Odie' });

        // Alternatively, patch Mokapi's autogenerated response and just set the name
        // response.data = patch(response.data, { name: 'Odie' });
    });
} 
Enter fullscreen mode Exit fullscreen mode

This example demonstrates how you can generate valid mock data that conforms to the API specification and then customize only the parts relevant to your test—such as setting a specific pet name—without redefining the entire response structure.

Making Acceptance Testing Sustainable

By combining flexible mocks, specification validation, and a smart patching mechanism, Mokapi makes acceptance testing more resilient, more focused, and easier to maintain. It helps your team test confidently—whether you're building a new feature in isolation, validating complex integrations, or preparing for a production release.

Mokapi doesn’t just enable acceptance testing—it makes it practical, maintainable, and deeply aligned with your evolving system and its requirements.

Ready to get started?

Learn how to set up acceptance tests with Mokapi in your CI/CD pipeline:

👉 Running Mokapi in a CI/CD Pipeline
👉 Mokapi Documentation

Comments 0 total

Загрузка комментариев...
Add comment