Lesson 2 of 4 · Free to read
Exercises
Exercises — Testing & Quality
Watch & learn
Course video
Course video
Keep a prompt log while you work. Speed without a trail is not a skill — it is luck.
Exercise 1 — Identify the pyramid layer
Goal: classify 10 test descriptions as unit / integration / E2E. Time: 15 minutes Level: foundational
Steps
- Read
code-examples/python/testcontainers_lab/PYRAMID.md. - For each test, label and justify.
Success criteria
- All 10 labelled; ≥1 disagreement defended in pair discussion.
AI prompt hints
- "Critique my labels; is anything boundary-ambiguous?"
Solution sketch
Watch for "calls external API" (integration) vs "uses an HTTP client to localhost mock" (unit).
Stretch
- Add 2 of your own; trade with a partner.
Exercise 2 — Write an integration test with Testcontainers
Goal: spin up Postgres via Testcontainers and write one integration test against the lab service. Time: 35 minutes Level: intermediate
Steps
cd code-examples/python/testcontainers_lab/; install.- Write a fixture for Postgres (session-scoped).
- Write one test that exercises the DB layer end-to-end.
- Run.
Success criteria
- Test passes locally with Docker.
- Fixture is session-scoped; state reset per test.
AI prompt hints
- "Generate a session-scoped Postgres fixture for testcontainers-python. Output only the fixture function."
Solution sketch
The common error: per-test container start = slow. Session-scoped + truncate-per-test = fast + isolated.
Exercise 3 — Grade AI-generated tests
Goal: generate ≥5 tests with AI; for each, decide keep / reject / modify with reasoning. Time: 35 minutes Level: intermediate
Steps
- Pick a function in the lab service.
- Ask AI to generate 5 tests.
- For each, log: tests behaviour or implementation? Locks you in to a refactor? Keep / reject / modify, why.
- Apply the kept tests; run; confirm green.
Success criteria
- 5 tests assessed with reasoning.
- Final test suite still green.
AI prompt hints
- "Generate 5 pytest tests for
f. Aim for behaviour, not implementation."
Solution sketch
Strong learners reject tests that lock specific call sequences. Weak ones keep all 5.
Stretch
- Refactor the function; see which generated tests survive.