Testing Basic
This section is meant to be read in order: first learn which test catches which bug, then learn why tests lose their signal and how to fix them, then load testing and testing against real dependencies.
It suits backend developers new to writing tests, or tech leads cleaning up a CI that keeps going red for no reason. The section does not yet cover mutation testing or frontend testing.
Reading path
Section titled “Reading path”| # | Article | You will be able to answer | Level | Read |
|---|---|---|---|---|
| 1 | Unit, integration, e2e | Which layer should catch this bug? When do you need a real DB or a contract test? Pyramid or trophy? | Basic | ~12 min |
| 2 | Flaky tests | Why does a test flip between green and red? How do you fix clock, ordering, shared state and async issues? When do you quarantine? | Basic | ~12 min |
| 3 | Load testing with k6 | How many RPS can the API take at the target p95? Why does a closed model hide a slow server? How do thresholds fail CI? | Intermediate | ~15 min |
| 4 | Testcontainers | How do you run tests against real Postgres, Redis and Kafka without slow, shared state? Rollback, truncate or template database? | Intermediate | ~15 min |
Article 2 assumes you already understand the test-layer boundaries from article 1.
If you run into…
Section titled “If you run into…”| Symptom | Read |
|---|---|
| Unit tests are green but production still breaks on a response/field | Which bug, which test layer |
| A mocked repository passes but production hits a unique constraint error | Real database and Testcontainers |
| Two services drift apart on the API schema after a deploy | Contract tests |
| CI is red, a rerun is green | Classifying flaky causes |
A TTL/expiry test uses sleep and fails often |
Sleep and an injected clock |
| Fails only when run in parallel or as a full suite | Classifying flaky causes |
| The team is used to retrying until green | Quarantine and flake policy |
Related
Section titled “Related”Test boundaries are easier to draw when code boundaries are clear: the Strategy pattern separates what varies into an independently testable policy, and the modular monolith discusses boundaries at the module level. For persistence risks see ACID and transactions.