CompCode Academy

Lesson 2 of 4 · Free to read

Exercises

Exercises — Testing & Quality

Watch & learn

Course video

Open on YouTube
JavaScript Testing with Jest — Crash Course — Test structure AI should generate and you should own.

Course video

Open on YouTube
GitHub Actions Tutorial — CI/CD Pipeline — Pipelines that gate AI-generated changes.

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

  1. Read code-examples/python/testcontainers_lab/PYRAMID.md.
  2. 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

  1. cd code-examples/python/testcontainers_lab/; install.
  2. Write a fixture for Postgres (session-scoped).
  3. Write one test that exercises the DB layer end-to-end.
  4. 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

  1. Pick a function in the lab service.
  2. Ask AI to generate 5 tests.
  3. For each, log: tests behaviour or implementation? Locks you in to a refactor? Keep / reject / modify, why.
  4. 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.

New free lessons and course updates. Unsubscribe from any email.