One test per question, each writing and asserting its own transcript under output/. Covers lifecycle, extensions, parameterized and dynamic tests, mocks vs spies, verification, strict stubs, static and constructor mocking, and flaky tests. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CifR2BE7PBvRy5hT8TS9oz
22 lines
1.3 KiB
Markdown
22 lines
1.3 KiB
Markdown
# junit-mockito
|
|
|
|
Companion code for **Top 30 JUnit 6 and Mockito Interview Questions (2026)** on ankurm.com.
|
|
|
|
One test method per question (`src/test/java/lab/jm/A_...F_*`, methods named `qNN_...`). Each test writes its own transcript to `output/qNN-*.txt` and asserts the same facts, so an answer in the article that stops being true fails the build. Questions 2 and 27 also have a script, because they need two different jar versions (Q2) and a JVM started without the Mockito agent (Q27).
|
|
|
|
| Component | Version |
|
|
|---|---|
|
|
| JUnit (Platform, Jupiter) | 6.1.3 |
|
|
| Mockito (`mockito-core`, `mockito-junit-jupiter`) | 5.24.0 |
|
|
| Maven Surefire | 3.6.0 |
|
|
| JDK | 25.0.5 (Temurin) |
|
|
|
|
```bash
|
|
./scripts/run-all.sh # runs the 28 test methods, then the two scripts; rewrites output/
|
|
mvn test # tests only
|
|
```
|
|
|
|
Test classes under `src/test/java/lab/jm/fixtures/` are launched on purpose through the JUnit Launcher API by the answer tests (to observe lifecycle order, failures, skips). Their names end in `Fixtures`, so Surefire does not run them directly; if your IDE offers to run them, some contain a deliberately failing test.
|
|
|
|
Surefire starts the test JVM with `-javaagent:` pointing at `mockito-core`, which is the setup Mockito recommends on current JDKs. `scripts/no-agent.sh` removes it to reproduce the warning described in Q27.
|