Skip to the content
Know your tech before you buy it. Makers: get listed from $49/mo

MockWebServer

square.github.io

  • Free plan
  • Android
7.4 Club score Visit square.github.io

What MockWebServer is

MockWebServer is a free, open-source test library for developers checking how apps make HTTP, HTTPS, or HTTP/2 requests. It runs as a scriptable web server: tests can supply responses and inspect requests made by an app. Recorded details include method, path, HTTP version, body, headers, and chunk sizes. Tests can queue canned responses or use a Dispatcher to choose a response policy for each request. Responses can be throttled to imitate a slow network, and socket policies can keep connections open, disconnect during requests or response bodies, or send no response. The README includes examples in Java and Kotlin and documents the test dependency com.squareup.okhttp3:mockwebserver3:5.5.0, available through Maven Central. The library is intended for internal and basic testing of apps using OkHttp, rather than as a full-featured standalone HTTP testing library. The project says it is not actively developed for new features and suggests MockServer when requirements grow beyond its intended scope. It is licensed under Apache License, Version 2.0.

Who it suits

MockWebServer suits developers writing internal or basic tests for apps that use OkHttp. It is a fit for Java and Kotlin test setups that need to script responses and inspect client requests.

Good to know, and what to watch

  • Tests HTTP, HTTPS, and HTTP/2 clients
  • Records request methods, paths, bodies, and headers
  • Can throttle responses to simulate slow networks
  • Includes Java and Kotlin examples
  • Available from Maven Central
  • Intended for internal and basic client testing
  • Not a full-featured standalone HTTP testing library
  • Not actively developed for new features

MockWebServer

Free

Open source

Free

Open source

The verdict

MockWebServer gives OkHttp app tests a way to control server responses and examine client requests, including under simulated network conditions. Teams needing a broader standalone testing library may need to look beyond its stated scope.

What the maker publishes

Alternative
The project documentation suggests MockServer for users whose needs outgrow MockWebServer. source
Distribution
The documented dependency is testImplementation("com.squareup.okhttp3:mockwebserver3:5.5.0"), available through Maven Central. source
Installation
The README lists the test dependency as com.squareup.okhttp3:mockwebserver3:5.5.0. source
Integrations
The project documentation describes using MockWebServer to test apps that use the OkHttp client. source
Integrations
Optional artifacts provide JUnit 4 and JUnit 5 integrations, while the core mockwebserver3 module has no JUnit dependency. source
Intended audience
The project describes MockWebServer as being used for internal testing and basic testing of apps using the OkHttp client. source
License
The MockWebServer README states that the library is licensed under Apache License, Version 2.0. source
License
The project page includes the Apache License, Version 2.0. source
Protocols
OkHttp describes MockWebServer as a library for testing HTTP, HTTPS, and HTTP/2 clients. source
Purpose
MockWebServer is a scriptable web server for testing HTTP clients. source
Purpose
MockWebServer is a library for testing HTTP, HTTPS, and HTTP/2 clients. source
Request capture
Its API exposes recorded requests, including request method, target, version, body, and chunk sizes. source
Request verification
Recorded requests can be checked by method, path, HTTP version, body, and headers. source
Responses
It is a scriptable web server that replays supplied canned responses in sequence when requested. source
Response scripting
Responses can be queued in order or generated by a Dispatcher that applies a policy to each request. source
Scope limit
The OkHttp project says MockWebServer is intended for internal and basic client testing, is not a full-featured standalone HTTP testing library, and is not actively developed for new features. source
Scope limit
The project says MockWebServer is not a full featured standalone HTTP testing library and is not actively developed for new features. source
Security
The docs state that MockWebServer can test HTTP, HTTPS, and HTTP/2 clients; they do not state security certifications or compliance claims. source
Simulated network conditions
Mock responses can be throttled to simulate a slow network for timeout and interactive testing. source
Socket behavior
Socket policies include behaviors such as keeping a socket open, disconnecting during a request or response body, and sending no response. source
Support
The project directs users to report issues encountered on GraalVM, but does not state a MockWebServer support plan or response time. source
Test coverage
It lets developers specify responses and verify requests made by an app during HTTP and HTTPS calls. source
Test languages
The README provides example tests in both Java and Kotlin. source

Checked against the maker's pages on 7 Oct 2026.