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.
- Host: GitHub
- URL: https://github.com/vashishthask/mocktail
- Owner: vashishthask
- Created: 2012-02-09T13:20:43.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2026-04-03T08:17:48.000Z (3 days ago)
- Last Synced: 2026-04-03T14:44:33.307Z (3 days ago)
- Topics: betamax, database, dependencies, interfaces, java, mocking, rest-api, restful-api, testing, vcr
- Language: Java
- Homepage:
- Size: 1.07 MB
- Stars: 14
- Watchers: 2
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
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