All Projects → httptoolkit → Mockttp

httptoolkit / Mockttp

Licence: mit
Powerful friendly HTTP mock server & proxy

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Mockttp

Smocker
Smocker is a simple and efficient HTTP mock server and proxy.
Stars: ✭ 465 (+34.39%)
Mutual labels:  proxy, integration-testing, mock-server
Mitm Scripts
🔄 A collection of mitmproxy inline scripts
Stars: ✭ 109 (-68.5%)
Mutual labels:  proxy, testing-tools, mock-server
mocat
🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.
Stars: ✭ 27 (-92.2%)
Mutual labels:  mock-server, testing-tools
chuck
Lightweight proxy for REST API mocking and run integration test on mobile devices
Stars: ✭ 17 (-95.09%)
Mutual labels:  integration-testing, mock-server
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (-84.68%)
Mutual labels:  integration-testing, testing-tools
Hoverfly
Lightweight service virtualization/API simulation tool for developers and testers
Stars: ✭ 1,814 (+424.28%)
Mutual labels:  proxy, testing-tools
go-smtp-mock
SMTP mock server written on Golang. Mimic any 📤 SMTP server behavior for your test environment with fake SMTP server.
Stars: ✭ 76 (-78.03%)
Mutual labels:  mock-server, testing-tools
karate
Test Automation Made Simple
Stars: ✭ 6,384 (+1745.09%)
Mutual labels:  mock-server, testing-tools
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (-89.02%)
Mutual labels:  proxy, mock-server
servirtium-java
Service Virtualized HTTP - to help service test automation stay fast and consistent
Stars: ✭ 16 (-95.38%)
Mutual labels:  mock-server, testing-tools
pactum
REST API Testing Tool for all levels in a Test Pyramid
Stars: ✭ 190 (-45.09%)
Mutual labels:  integration-testing, mock-server
conex
Conex integrates Docker with testing package so you can easily run your integration tests with containers.
Stars: ✭ 79 (-77.17%)
Mutual labels:  integration-testing, testing-tools
Hoverfly Java
Java binding for Hoverfly
Stars: ✭ 130 (-62.43%)
Mutual labels:  proxy, testing-tools
ruby-dns-mock
DNS mock server written on 💎 Ruby. Mimic any DNS records for your test environment with fake DNS server.
Stars: ✭ 50 (-85.55%)
Mutual labels:  mock-server, testing-tools
Mockserver Client Node
MockServer javascript client for browsers, Node.js or any grunt build
Stars: ✭ 52 (-84.97%)
Mutual labels:  proxy, mock-server
main
Mocks Server monorepo
Stars: ✭ 109 (-68.5%)
Mutual labels:  mock-server, testing-tools
Stubby4j
An HTTP stub server for testing application interactions with web services (REST, etc) & external system stubbing for easy testing
Stars: ✭ 300 (-13.29%)
Mutual labels:  integration-testing, mock-server
Lyrebird
移动应用插件化测试工作台
Stars: ✭ 663 (+91.62%)
Mutual labels:  proxy, testing-tools
kheera-testrunner-android
BDD Framework for Android
Stars: ✭ 18 (-94.8%)
Mutual labels:  integration-testing, testing-tools
Chn Eolinker Ams Lite 4.0 For Java
中国最大的API接口管理平台,3.x开源发行版,支持多国语言[英语、简体中文、繁体中文]
Stars: ✭ 275 (-20.52%)
Mutual labels:  testing-tools, mock-server

Mockttp Build Status Available on NPM Try Mockttp on RunKit

Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S)

Mockttp lets you quickly & reliably test HTTP requests & responses in JavaScript, in both Node and browsers.

There's a lot of tools to do this, but typically by stubbing the HTTP functions in your process at the JS level. That ties you to a specific environment, doesn't test the real requests that'd be made, and only works for requests made in the same JS processs. It's inflexible, limiting and inaccurate, and often unreliable & tricky to debug too.

Mockttp is here to make this better.

Mockttp allows you to do accurate true integration testing, writing one set of tests that works out of the box in node or browsers, with support for transparent proxying & HTTPS, strong typing & promises throughout, fast & safe parallel testing, and helpful built-in debuggability support all the way down.

Features

Let's get specific. Mockttp lets you:

  • Write easy, fast & reliable node.js & browser HTTP integration tests
  • Stub server responses and verify HTTP requests made by your code
  • Intercept HTTPS too, with built-in self-signed certificate generation
  • Mock requests inside or outside your process/tab, including subprocesses, native code, remote devices, and more
  • Test true real-world behaviour, verifying the real requests made, and testing exactly how your whole stack will handle a response in reality
  • Stub direct requests, or transparently stub requests elsewhere as an HTTP mocking proxy
  • Mock for node & browser tests with the same code (universal/'isomorphic' HTTP mocking)
  • Safely mock HTTP in parallel, with autoconfiguration of ports, mock URLs and proxy settings, for super-charged integration testing
  • Debug your tests easily, with full explainability of all mock matches & misses, mock autosuggestions, and an extra detailed debug mode
  • Write modern test code, with promises all the way down, async/await, and strong typing (with TypeScript) throughout

Get Started

npm install --save-dev mockttp

Get Testing

To run an HTTP integration test, you need to:

  • Start a Mockttp server
  • Mock the endpoints you're interested in
  • Make some real HTTP requests
  • Assert on the results

Here's a simple minimal example of all that using plain promises, Mocha, Chai & Superagent, which works out of the box in Node and modern browsers:

const superagent = require("superagent");
const mockServer = require("mockttp").getLocal();

describe("Mockttp", () => {
    // Start your server
    beforeEach(() => mockServer.start(8080));
    afterEach(() => mockServer.stop());

    it("lets you mock requests, and assert on the results", () =>
        // Mock your endpoints
        mockServer.get("/mocked-path").thenReply(200, "A mocked response")
        .then(() => {
            // Make a request
            return superagent.get("http://localhost:8080/mocked-path");
        }).then(response => {
            // Assert on the results
            expect(response.text).to.equal("A mocked response");
        })
    );
});

(Want to play with this yourself? Try running a standalone version live on RunKit: https://npm.runkit.com/mockttp)

That is pretty easy, but we can make this simpler & more powerful. Let's take a look at some more fancy features:

const superagent = require("superagent");
require('superagent-proxy')(superagent);
const mockServer = require("mockttp").getLocal();

describe("Mockttp", () => {
    // Note that there's no start port here, so we dynamically find a free one instead
    beforeEach(() => mockServer.start());
    afterEach(() => mockServer.stop());

    it("lets you mock without specifying a port, allowing parallel testing", async () => {
        // Simplify promises with async/await in supported environments (Chrome 55+/Node 8+/Babel/TypeScript)
        await mockServer.get("/mocked-endpoint").thenReply(200, "Tip top testing")

        // Try mockServer.url or .urlFor(path) to get a the dynamic URL for the server's port
        let response = await superagent.get(mockServer.urlFor("/mocked-endpoint"));

        expect(response.text).to.equal("Tip top testing");
    });

    it("lets you verify the request details the mockttp server receives", async () => {
        const endpointMock = await mockServer.get("/mocked-endpoint").thenReply(200, "hmm?");

        await superagent.get(mockServer.urlFor("/mocked-endpoint"));

        // Inspect the mock to get the requests it received and assert on their details
        const requests = await endpointMock.getSeenRequests();
        expect(requests.length).to.equal(1);
        expect(requests[0].url).to.equal(`http://localhost:${mockServer.port}/mocked-endpoint`);
    });

    it("lets you proxy requests made to any other hosts", async () => {
        // Match a full URL instead of just a path to mock proxied requests
        await mockServer.get("http://google.com").thenReply(200, "I can't believe it's not google!");

        // One of the many ways to use a proxy - this assumes Node & superagent-proxy.
        // In a browser, you can simply use the browser settings instead.
        let response = await superagent.get("http://google.com").proxy(mockServer.url);

        expect(response.text).to.equal("I can't believe it's not google!");
    });
});

These examples uses Mocha, Chai and Superagent, but none of those are required: Mockttp will work with any testing tools that can handle promises (and with minor tweaks, many that can't), and can mock requests from any library, tool or device you might care to use.

Documentation

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].