Easy mocking of any system you integrate with via HTTP or HTTPS

Fork us on GitHub Build Status Travis Build Status

What is MockServer

MockServer can be used for mocking any system you integrate with via HTTP or HTTPS (i.e. services, web sites, etc).

MockServer can:

  • return a "mock" response when a request matches an expectation
  • forward a request when the request matches an expectation (i.e. a dynamic port forwarding proxy)
  • execute a callback when a request matches an expectation, allowing the response to be created dynamically
  • verify requests have been sent (i.e. as a test assertion)

What is MockServer Proxy

MockServer Proxy can be used for transparently recording all requests sent by a system (i.e. an application or set of applications).

MockServer Proxy can:

  • proxy all requests using any of the following proxying methods:
    • Port Forwarding
    • Web Proxying (i.e. HTTP proxy)
    • HTTPS Tunneling Proxying (using HTTP CONNECT)
    • SOCKS Proxying (i.e. dynamic port forwarding)
  • verify requests have been sent (i.e. in a test assertion)
  • record requests and responses to analyse how a system behaves

The MockServer Proxy provides the following features:

  • Port forwarding
    • all requests for a specific local port are forwarded to a different (local or remote) port and hostname
    • the client must use the hostname and port of the MockServer Proxy instead of the system being proxied
  • Web proxying (i.e. HTTP proxy)
    • all requests are forwarded using the Host header of the HTTP request
    • the client must be configured to use an HTTP Proxy
  • HTTPS tunneling proxying (using HTTP CONNECT)
    • all requests are forwarded using a CONNECT request
    • the client must be configured to use an HTTP Proxy
  • SOCKS proxying (i.e. dynamic port forwarding)
    • all requests are forwarded to port and hostname when socket connection is created
    • the operating system (or JVM) must be configured to use an HTTP Proxy
  • SSL & Certificates
  • Port Unification
    • to simplify configuration for both the MockServer and Proxy all protocols (i.e. HTTP, HTTPS / SSL, SOCKS, etc) are supported on the same port, as the protocol being used is dynamically detected

Why use MockServer

MockServer allows you to mock any server or service that you connect to over HTTP or HTTPS, such as a REST or RPC service.

This is useful in the following scenarios:

  • testing
    • easily recreate all types of responses for HTTP dependencies such as REST or RPC services to test applications easily and affectively
    • isolate the system under test to ensure tests run reliably and only fail when there is a genuine bug. It is important only the system under test is tested and not its dependencies to avoid tests failing due to irrelevant external changes such as network failure or a server being rebooted / redeployed.
    • easily setup mock responses independently for each test to ensure test data is encapsulated with each test. Avoid sharing data between tests that is difficult to manage and maintain and risks tests infecting each other
    • create test assertions that verify the requests the system-under-test has sent
  • de-coupling development
    • start working against a service API before the service is available. If an API or service is not yet fully developed MockServer can mock the API allowing any team who is using the service to start work without being delayed
    • isolate development teams particularly critical during the initial development phases when the APIs / services may be extremely unstable and volatile. Using MockServer allows development work to continue even when an external service fails
  • isolate single service
    • during deployment and debugging it is helpful to run a single application or service or handle a sub-set of requests on on a local machine in debug mode. Using MockServer it is easy to selectively forward requests to a local process running in debug mode, all other request can be forwarded to the real services for example running in a QA or UAT environment

A system with service dependencies as follows:

System In Production

MockServer could be used to mock the service dependencies, as follows:

Mocking service dependencies with MockServer

Why use MockServer Proxy

MockServer proxy allows you to record request from the system-under-test or two analysis an existing system by recording outbound requests.

This is useful in the following scenarios:

  • testing
    • create test assertions that verify the requests the system-under-test has been sent, without needing to mock any requests
  • analyse existing system
    • record all outbound requests so it is possible to analise and under stand what outbound requests an existing system is making
  • debug HTTP interactions
    • log all outbound requests so it is possible to visualise all interactions (for example from a browser) to external services. This is particularly important as network analysis tools in browsers such as Chrome do not accurately show all network interactions, such as, favicon.ico requests. In addition many proxies do not handle encrypted HTTPS traffic, however, MockServer Proxy auto-generates certificates using a single MockServer root CA certificate enabling the root certificate to be easily imported
  • record & replay
    • all recorded requests can be converted into Java code or JSON expectations to simplify the creation of mocks for complex test scenarios

MockServer Proxy could be used to verify service requests, as follows:

Verifying service request with MockServer Proxy