First integration test
Use Mokksy when your code normally calls an external HTTP API: payments, customer data, fraud scoring, telecom provisioning, document processing, or internal platform services.
1Application under test -> Mokksy -> Stubbed external HTTP API
Test shape
- Start Mokksy on a random local port.
- Configure the application under test to use
mokksy.baseUrl(). - Stub the external endpoint and response.
- Execute the real application behavior.
- Verify the response and the request journal.
Example
1val mokksy = Mokksy(verbose = true).start()
2val client = HttpClient {
3 install(DefaultRequest) {
4 url(mokksy.baseUrl())
5 }
6}
7
8mokksy.post {
9 path("/risk/check")
10 bodyContains("customer-123")
11} respondsWith {
12 httpStatus = HttpStatusCode.Accepted
13 body = """{"decision":"review"}"""
14}
15
16val response = client.post("/risk/check") {
17 contentType(ContentType.Application.Json)
18 setBody("""{"customerId":"customer-123","amount":2500}""")
19}
20
21response.status shouldBe HttpStatusCode.Accepted
22response.bodyAsText() shouldBe """{"decision":"review"}"""
23
24mokksy.verifyNoUnexpectedRequests()
25mokksy.verifyNoUnmatchedStubs() 1var mokksy = Mokksy.create().start();
2var httpClient = HttpClient.newHttpClient();
3
4try {
5 mokksy.post(spec -> spec
6 .path("/risk/check")
7 .bodyContains("customer-123")
8 ).respondsWith(response -> response
9 .status(202)
10 .body("{\"decision\":\"review\"}"));
11
12 var response = httpClient.send(
13 HttpRequest.newBuilder()
14 .uri(URI.create(mokksy.baseUrl() + "/risk/check"))
15 .header("Content-Type", "application/json")
16 .POST(HttpRequest.BodyPublishers.ofString(
17 "{\"customerId\":\"customer-123\",\"amount\":2500}"
18 ))
19 .build(),
20 HttpResponse.BodyHandlers.ofString()
21 );
22
23 assertThat(response.statusCode()).isEqualTo(202);
24 assertThat(response.body()).isEqualTo("{\"decision\":\"review\"}");
25
26 mokksy.verifyNoUnexpectedRequests();
27} finally {
28 mokksy.shutdown();
29}This catches two important integration failures: your code sent the wrong request, or it did not call the dependency at all.