--- title: Getting Started Mocking description: Step-by-step guide to starting MockServer, creating your first expectation, running tests against it, and verifying requests. shortTitle: Getting Started layout: page pageOrder: 1 section: 'Mock Server' subsection: true sitemap: priority: 0.9 changefreq: 'monthly' lastmod: 2019-11-10T08:00:00+01:00 ---

Note: this page is a high level overview of each topic, more detail is available for each topic on a linked page.

The typical sequence for using MockServer is as follows:

  1. Start MockServer
  2. Setup Expectations
  3. Run Your Test Scenarios
  4. Verify Requests

Mocking service dependencies with MockServer

For example code see the code examples folder in the git repository.

 

0. Start MockServer

{% include_subpage _includes/running_mock_server_summary.html %}  

1. Setup Expectations

{% include_subpage _includes/creating_expectations.html %}

2. Run Your Test Scenarios

With MockServer running and expectations configured, execute your application or test suite. Your application should make requests to MockServer (on the configured port) instead of the real dependencies. MockServer will match incoming requests against the configured expectations and return the specified responses.

 

3. Verify Requests

{% include_subpage _includes/verification_summary.html %}  

Spring Boot Compatibility

MockServer targets Java 17 as the minimum supported version and uses the javax namespace throughout. This means MockServer is compatible with Spring Boot 2.x (which uses Spring Framework 5.x) but is not compatible with Spring Boot 3.x (which uses Spring Framework 6.x).

Spring Boot 3 migrated from the javax namespace to the jakarta namespace. If your project uses Spring Boot 3, you can still use MockServer as a standalone Docker container or process, but the Spring Test Execution Listener and JUnit integrations that depend on Spring classpath integration are not supported.

Spring Boot Version Spring Framework Namespace MockServer Compatible
2.x 5.x javax Yes
3.x 6.x jakarta No (use Docker or standalone)
 

Upgrading MockServer

When upgrading MockServer between versions, be aware of the following changes that may affect your setup:

It is recommended to run your full test suite after upgrading to catch any compatibility issues early.

 

HTTP/2 Proxy Limitations

MockServer can accept HTTP/2 connections and serve mock responses over HTTP/2. However, when MockServer is used as a proxy and forwards requests to downstream services, HTTP/2 requests are downgraded to HTTP/1.1. This means:

If your tests require end-to-end HTTP/2 proxying (including HTTP/2 to the upstream server), this is not currently supported. Consider using MockServer in mock mode instead of proxy mode for HTTP/2 endpoints.

 

Single Port Architecture

MockServer serves both mock and proxy traffic on the same port (default 1080). There is no separate port for proxying. The proxyRemotePort and proxyRemoteHost settings specify the upstream target server that unmatched requests are forwarded to — they do not open a separate listening port. All expectations, proxy forwarding, and protocol support (HTTP, HTTPS, SOCKS) share the single serverPort.