Convert Figma logo to code with AI

mountebank-testing logomountebank

Over the wire test doubles

2,031
292
2,031
96

Top Related Projects

Over the wire test doubles

A tool for mocking HTTP services

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

16,988

Industry standard API mocking for JavaScript.

7,563

Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.

Quick Overview

Mountebank is an open-source tool for creating test doubles (mocks, stubs, and proxies) over the network. It allows developers to simulate external dependencies in their tests, enabling faster and more reliable testing of distributed systems. Mountebank supports multiple protocols and provides a flexible API for configuring test doubles.

Pros

  • Supports multiple protocols (HTTP, HTTPS, TCP, and more)
  • Easy to set up and configure using JSON or JavaScript
  • Provides a RESTful API for programmatic control
  • Can be run as a standalone server or embedded in Node.js applications

Cons

  • Learning curve for complex scenarios
  • Limited built-in validation for imposter configurations
  • Documentation can be overwhelming for beginners
  • Performance may degrade with a large number of imposters

Code Examples

  1. Creating a simple HTTP stub:
const mb = require('mountebank');
const settings = {
  port: 2525,
  pidfile: './mb.pid',
  logfile: './mb.log',
  protofile: './protofile.json',
  ipWhitelist: ['*']
};

mb.create(settings).then(() => {
  mb.post('/imposters', {
    port: 4545,
    protocol: 'http',
    stubs: [{
      predicates: [{ equals: { method: 'GET', path: '/test' } }],
      responses: [{ is: { statusCode: 200, body: 'Hello, World!' } }]
    }]
  });
});
  1. Creating a TCP proxy:
mb.post('/imposters', {
  port: 5555,
  protocol: 'tcp',
  mode: 'proxy',
  proxy: {
    to: 'tcp://real-service:1234'
  }
});
  1. Using JavaScript predicates and responses:
mb.post('/imposters', {
  port: 6565,
  protocol: 'http',
  stubs: [{
    predicates: [{
      javascript: function (request) {
        return request.method === 'POST' && request.path === '/api/data';
      }
    }],
    responses: [{
      inject: function (request, state, logger) {
        const data = JSON.parse(request.body);
        return {
          statusCode: 201,
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ id: state.id++, ...data })
        };
      }
    }]
  }]
});

Getting Started

  1. Install Mountebank:

    npm install -g mountebank
    
  2. Start Mountebank:

    mb
    
  3. Create an imposter (e.g., HTTP stub on port 4545):

    curl -X POST http://localhost:2525/imposters -H "Content-Type: application/json" -d '{
      "port": 4545,
      "protocol": "http",
      "stubs": [{
        "predicates": [{ "equals": { "path": "/test" } }],
        "responses": [{ "is": { "statusCode": 200, "body": "Hello, World!" } }]
      }]
    }'
    
  4. Test the imposter:

    curl http://localhost:4545/test
    

Competitor Comparisons

Over the wire test doubles

Pros of mountebank

  • More comprehensive documentation and examples
  • Larger community and more active development
  • Supports a wider range of protocols and use cases

Cons of mountebank

  • Steeper learning curve for beginners
  • Requires more setup and configuration
  • Potentially overkill for simple mocking scenarios

Code Comparison

mountebank:

const mb = require('mountebank');
const settings = {
  port: 2525,
  pidfile: './mb.pid',
  logfile: './mb.log',
  protofile: './protofile.json',
  ipWhitelist: ['*']
};
mb.create(settings);

mountebank>:

const mb = require('mountebank');
mb.create({
  port: 2525,
  pidfile: './mb.pid',
  logfile: './mb.log'
});

The code comparison shows that mountebank> has a simpler setup process with fewer configuration options, while mountebank offers more granular control over settings like protocol files and IP whitelisting.

Both repositories serve as testing tools for creating test doubles, but mountebank is more feature-rich and widely adopted. mountebank> appears to be a simplified version or fork of the original mountebank project, potentially aimed at users who prefer a more streamlined experience with fewer configuration options.

A tool for mocking HTTP services

Pros of WireMock

  • More extensive HTTP protocol support, including WebSockets
  • Better integration with Java ecosystem and JUnit
  • More flexible request matching capabilities

Cons of WireMock

  • Primarily Java-focused, less language-agnostic than Mountebank
  • Steeper learning curve for non-Java developers
  • Less built-in support for non-HTTP protocols

Code Comparison

WireMock stub example:

stubFor(get(urlEqualTo("/api/resource"))
    .willReturn(aResponse()
        .withStatus(200)
        .withHeader("Content-Type", "application/json")
        .withBody("{\"message\":\"Hello, World!\"}")));

Mountebank stub example:

{
  "predicates": [{ "equals": { "path": "/api/resource", "method": "GET" } }],
  "responses": [{
    "is": {
      "statusCode": 200,
      "headers": { "Content-Type": "application/json" },
      "body": { "message": "Hello, World!" }
    }
  }]
}

Both WireMock and Mountebank are powerful service virtualization tools, but they cater to different ecosystems and use cases. WireMock excels in Java environments with its deep integration and extensive HTTP capabilities, while Mountebank offers a more language-agnostic approach and broader protocol support beyond HTTP.

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

Pros of json-server

  • Simpler setup and configuration for basic REST API mocking
  • Built-in support for JSON data sources without additional scripting
  • Automatic generation of routes based on JSON structure

Cons of json-server

  • Limited functionality for complex API behaviors and responses
  • Lacks advanced features like TCP/UDP protocol support and HTTPS
  • No built-in support for stateful imposter behavior

Code Comparison

json-server:

// Start the server with a JSON file
json-server --watch db.json

// Define custom routes
{
  "/api/*": "/$1",
  "/:resource/:id/show": "/:resource/:id"
}

mountebank:

{
  "imposters": [{
    "port": 4545,
    "protocol": "http",
    "stubs": [{
      "predicates": [{ "equals": { "method": "GET", "path": "/users" } }],
      "responses": [{ "is": { "statusCode": 200, "body": [{"id": 1, "name": "John"}] } }]
    }]
  }]
}

While json-server excels in simplicity for basic REST API mocking, mountebank offers more advanced features for complex API simulation. json-server is ideal for quick prototyping and simple scenarios, whereas mountebank provides greater flexibility and control over imposter behavior, supporting multiple protocols and sophisticated response manipulation.

16,988

Industry standard API mocking for JavaScript.

Pros of MSW

  • Runs in the browser, allowing for more realistic mocking of network requests
  • Seamless integration with modern JavaScript frameworks and testing libraries
  • Supports both REST and GraphQL APIs out of the box

Cons of MSW

  • Limited to mocking HTTP and HTTPS requests only
  • Requires more setup and configuration for non-browser environments

Code Comparison

MSW:

import { rest } from 'msw'
import { setupServer } from 'msw/node'

const server = setupServer(
  rest.get('/api/user', (req, res, ctx) => {
    return res(ctx.json({ name: 'John Doe' }))
  })
)

Mountebank:

const mb = require('mountebank');
const settings = {
  imposterPort: 4545,
  imposterProtocol: 'http',
  stubs: [{
    responses: [{ is: { statusCode: 200, body: { name: 'John Doe' } } }],
    predicates: [{ equals: { method: 'GET', path: '/api/user' } }]
  }]
};

Both MSW and Mountebank are powerful tools for mocking API responses, but they cater to different use cases. MSW excels in browser-based testing and modern JavaScript environments, while Mountebank offers more flexibility for various protocols and server-side testing scenarios. The choice between them depends on the specific requirements of your project and testing environment.

7,563

Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.

Pros of Mockoon

  • User-friendly GUI for creating and managing mock APIs
  • Supports OpenAPI specification import and export
  • Cross-platform desktop application (Windows, macOS, Linux)

Cons of Mockoon

  • Limited scripting capabilities compared to Mountebank
  • Lacks advanced features like TCP/SMTP protocol support
  • No built-in load testing or performance analysis tools

Code Comparison

Mockoon (JSON configuration):

{
  "uuid": "mockoon-api",
  "endpoints": [
    {
      "method": "GET",
      "path": "/users",
      "responses": [
        {
          "status": 200,
          "body": "[{\"id\": 1, \"name\": \"John\"}]"
        }
      ]
    }
  ]
}

Mountebank (JavaScript imposter):

{
  port: 4545,
  protocol: 'http',
  stubs: [{
    predicates: [{ equals: { method: 'GET', path: '/users' } }],
    responses: [{ is: { statusCode: 200, body: '[{"id": 1, "name": "John"}]' } }]
  }]
}

Both tools offer API mocking capabilities, but Mockoon focuses on simplicity and ease of use through its GUI, while Mountebank provides more advanced features and flexibility through its programmable approach.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Project in transition

Currently the project is in transition to a collaborative group effort under a github organisation.

Work is being done to migrate and upgrade all CI/CD integrations from personal accounts to organisation accounts.

Pull requests are welcome, but don't expect anything to be merged until CI/CD infrastucture is up and running.

Many thanks goes to Brandon Byars for all the effort building mountebank in the first place and maintaining the project for more than a decade and finally being helpfull and collaborative during this transition phase.

Welcome, friend

mountebank is the only open source service virtualization tool that competes with the commercial offerings in terms of protocol diversity, capability, and performance. Here's what Capital One wrote about their mobile cloud migration (emphasis theirs):

In fact, halfway through we discovered our corporate mocking software couldn’t handle the sheer amount of performance testing we were running as part of this effort (we completely crushed some pretty industrial enterprise software in the process). As a result, we made the call to move the entire program over to a Mountebank OSS-based solution with a custom provision to give us the ability to expand/shrink our mocking needs on demand.

At the moment, the following protocols are implemented, either directly in the tool or as a community extension:

  • http
  • https
  • tcp (text and binary)
  • smtp
  • ldap
  • grpc
  • websockets
  • graphql
  • snmp
  • telnet
  • ssh
  • netconf

mountebank supports mock verification, stubbing with advanced predicates, JavaScript injection, and record-playback through proxying.

how it works

See getting started guide for more information once you have it running locally.

Install and Run

Install:

npm install -g mountebank

Run:

mb

There are a number of command line options if you need to customize mountebank.

All pre-release versions of mountebank are available with the beta npm tag. No beta version is published unless it has passed all tests.

Learn More

After installing and running, view the docs in your browser at http://localhost:2525.

You can always learn more and support mountebank development by buying the book:

Testing Microservices with Mountebank

Building

There are two packages: mountebank itself, and a test package called mbTest (which houses all out-of-process tests against mountebank). First ensure all dependencies are installed for both packages:

npm install

Then, run all tests:

npm test

Several other test configurations exist. You can see the CI pipeline in .circleci/config.yml.

There are some tests that require network access. A few of these tests verify the correct behavior under DNS failures. If your ISP is kind enough to hijack the NXDOMAIN DNS response in an attempt to allow you to conveniently peruse their advertising page, those tests will fail. I suggest that, under such circumstances, you talk to your ISP and let them know that their policies are causing mountebank tests to fail. You can also set the environment variable MB_AIRPLANE_MODE=true, which will avoid tests requiring your DNS resolver.

NPM DownloadsLast 30 Days