mountebank - over the wire test doubles

Fork me on GitHub

the apothecary


Mocks are a type of test double that allow you to verify a call was made without relying on the server response. mountebank enables mocking through the requests element on an imposter. The fields saved for each request depends on the protocol, and are documented in the protocol pages linked to from the sidebar. It is up to the client code to implement the mock verification using the requests array.

Note, the --mock command line flag must be set to enable mock verification. Mocking requires mountebank to remember information about each request to each imposter. For long-running instances of mountebank, this represents a memory leak, so this functionality is turned off by default.


The SMTP protocol is one where mocking is very valuable, since most applications don't rely on complex SMTP responses, but it is useful to verify that the application sent an SMTP request without actually sending an email.

First let's create an imposter:

POST /imposters HTTP/1.1
Host: localhost:36003
Accept: application/json
Content-Type: application/json

  "port": 4545,
  "protocol": "smtp"

Now make the following SMTP request in your application:

From: "Customer Service" <>
To: "Customer" <>
Subject: Thank you for your order

Hello Customer,
Thank you for your order from  Your order will
be shipped shortly.

Your friendly customer service department.

You can verify the call by making either a GET or DELETE call to the imposter:

GET /imposters/4545 HTTP/1.1
Host: localhost:36003
Accept: application/json
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Vary: Accept
Content-Type: application/json; charset=utf-8
Content-Length: 991
Date: Thu, 09 Jan 2014 02:30:31 GMT
Connection: keep-alive

  "protocol": "smtp",
  "port": 4545,
  "numberOfRequests": 1,
  "requests": [
      "requestFrom": "::ffff:",
      "envelopeFrom": "",
      "envelopeTo": [""],
      "from": {
        "address": "",
        "name": "Customer Service"
      "to": [
          "address": "",
          "name": "Customer"
      "cc": [],
      "bcc": [],
      "subject": "Thank you for your order",
      "priority": "normal",
      "references": [],
      "inReplyTo": [],
      "text": "Hello Customer,\nThank you for your order from  Your order will\nbe shipped shortly.\n\nYour friendly customer service department.",
      "html": "",
      "attachments": [],
      "timestamp": "2015-01-09T02:30:31.850Z"
  "stubs": [],
  "_links": {
    "self": { "href": "http://localhost:36003/imposters/4545" }

Now you can use the requests element in your test code to validate the application sent the correct information.