An open API service indexing awesome lists of open source software.

https://github.com/vashishthask/mocktail

Mocktail is a tool to cache the response of potentially any Java method call on the disk.
https://github.com/vashishthask/mocktail

betamax database dependencies interfaces java mocking rest-api restful-api testing vcr

Last synced: 3 days ago
JSON representation

Mocktail is a tool to cache the response of potentially any Java method call on the disk.

Awesome Lists containing this project

README

          

# Mocktail 🍹

> Run integration tests 10× faster — no Docker, no hand-written stubs, no drifting fixtures.

Mocktail records the real response of **any Java method call** to disk on the first run, then replays it instantly on every run after. Think of it as VCR for your Java code — not just HTTP, but any method: JPA repositories, AWS SDKs, Kafka consumers, legacy DAOs, gRPC clients — all of it.

---

## The Problem

You have integration tests that call a database, an external SDK, or an internal service. Your choices today feel like a trade-off you can't win:

| Approach | The hidden cost |
|---|---|
| Testcontainers | 10–30s Docker startup per test suite. Breaks in airgapped CI. |
| WireMock | Only intercepts HTTP. Useless for JPA, SDKs, message buses. |
| Mockito stubs | Hand-written. Never match real data. Drift silently. |
| H2 in-memory | SQL dialect differences cause false passes and false failures. |

Mocktail is none of those. It captures the *real* response once, checks it into source control, and replays it from disk in milliseconds forever.

---

## Quick Start

### 1. Add the dependency

```xml

in.malonus.mocktail
mocktail-core
1.0.3
test

```

You also need the AspectJ compiler plugin to enable method interception:

```xml

org.codehaus.mojo
aspectj-maven-plugin
1.14.0

11


in.malonus.mocktail
mocktail-core





compiletest-compile

```

### 2. Configure which methods to intercept

Create `src/test/resources/mocktail.xml`:

```xml


com.example.UserRepository
findByEmail

```

**Modes:**
- `recording` — Record the response once; replay on every subsequent call (recommended for CI)
- `recording_new` — Always re-record, overwriting what's on disk (use to refresh fixtures)

### 3. Wrap your test

```java
@Test
void shouldReturnUserByEmail() throws Exception {
try (MethodMocktail m = new MethodMocktail(this)) {
User user = userRepository.findByEmail("jane@example.com");
assertThat(user.getName()).isEqualTo("Jane Doe");
}
}
```

That's it. On the first run Mocktail calls the real `findByEmail`, saves the response to disk under `src/test/resources/mocktail/`, and every run after that skips the database entirely.

---

## How It Works