Skip to main content

Updated for Fall 2026

This activity is part of Milestone 4; see that page for the milestone’s deliverables, rubric, and deadlines.

Can Your Tests Catch a Bug?

You have a coverage number. You do not yet have any evidence that your tests would notice if the code were wrong.

Those are different things, and the gap between them is larger than most people expect. A test that calls a method and asserts the result is not null executes every line of that method, which means it contributes to coverage exactly as much as a test that checks the answer. But the test is flawed since it will pass no matter what the method returns. The test isn’t checking anything meaningful! This is a potential problem when tests are created to make the coverage tool happy or for tests that are generated using an AI tool. Milestone 1 gave you a first look at this when generated tests raised coverage without finding anything. This activity measures it.

The technique is called mutation testing: change the code in a small, plausible way, and see whether the test suite fails. A mutation your tests do not catch is a hole in your suite, and it is a specific, fixable one since you know exactly what behavior is unverified. There are tools to support mutation testing, like PITest. AI tools can also help with this activity.

This is an individual activity. Complete it in your individual repository, against the UC6 Order Beverage code you implemented for Milestone 4. Do it after UC6 is implemented, tested, and merged.

Stage 1: Inject

Create a branch for this activity named unityID/mutation-m4 off your merged UC6 code. Nothing on this branch gets merged. You will read the injected bugs at the end, not the beginning.

Ask your AI assistant to introduce five bugs into your UC6 implementation:

Here is the implementation of Order Beverage in our coffee ordering system:
<paste MakeRecipeServiceImpl, MakeRecipeController, and anything else UC6
 touches>

Introduce exactly 5 bugs into this code. They must be subtle and plausible
-- the kind of mistake a tired developer makes, not obvious breakage.

Rules:
- Each bug must be a change of a few characters to a few lines.
- The code must still compile.
- Do not change any test.
- Do not add comments marking the bugs.

Give me the modified files, and separately -- so I can avoid reading it
until later -- a numbered list of what you changed and where.

Put that list somewhere you will not see it until Stage 3.

Bugs in this range are (hopefully) the useful kind:

  • an off-by-one in the change calculation
  • >= where > belongs on the sufficient-funds check
  • inventory not decremented after a successful order
  • two fields swapped in the mapper
  • the pre-update object returned instead of the saved one
  • an exception caught and swallowed instead of propagating

If you are not using AI, swap with a classmate: each of you injects five bugs into your own copy of the other’s UC6 code and hands back the modified files without the list. You MUST document who you swapped with.

Stage 2: Run

Add in the buggy code and run your test suite.

  • If a test fails, record caught, and which test caught it. Read the failure message and check that it points you at the real problem. A test that fails with expected: not <null> tells you much less than one that fails with expected: 25 but was: 30.
  • If everything passes, record escaped. Your suite executes that code and does not check what it does.

Record you coverage!

Stage 3: Fix the Suite

Now read the list of what was injected, and reconcile it with what you found. Check for the case where a test failed for a different reason than the bug you injected. It means you have a flaky or over-specified test worth looking at.

For every escaped bug, go back to your merged branch and write the test that would have caught the bug.

Then check coverage again. Did it change? Or was coverage about the same while the bug detection increased due to better tests?

Deliverable: technical-documents/test-effectiveness-m4.md, containing

  • a table with one row per injected bug

| # | What was changed | Where | Caught? | Test that caught it, or test you added | | - | —————- | —– | ——- | ————————————– |

  • your statement and branch coverage before and after
  • two or three sentences on what the escapes had in common

That last item is the interesting one. Escapes are rarely random. They tend to cluster around code that is executed on the way to something else.

Reflect

Record your reflection in retros/retro-m4.md in your individual repository. The milestone asks you specifically:

Which injected bug escaped your tests, and what does that tell you about the rest of your suite?

Beyond that:

  • How many of the five did you expect to be caught before you ran them? How many actually were?
  • Did your coverage number change meaningfully after you added the missing tests? What does that tell you about coverage as a measure of test quality?
  • Look at the tests your team wrote for UC2, UC4, UC5, and UC7. Do they have the same weakness? Say so in your team’s channel if they do — it is the same codebase, and Milestone 5 builds on it.

Done Criteria

  • Five bugs injected against a merged and tested UC6 implementation.
  • technical-documents/test-effectiveness-m4.md records all five with caught/escaped and the test involved.
  • A new test merged for every escape.
  • The throwaway branch is not merged.
  • retros/retro-m4.md is complete, including the escaped-bug question.