Skip to content

Traceability: requirement → design → test

Difficulty: Intermediate

Key concepts

  • traceability
  • traceability table
  • forward trace
  • backward trace
  • untested requirement
  • unjustified code
  • coverage gap
  • What traceability is: the links from each requirement to the design that implements it and the tests that check it.
  • How to build a traceability table from the IDs the earlier lessons gave every requirement, criterion, and test.
  • How to read it forwards (requirement → test) to find untested requirements, and backwards (code → requirement) to find code nobody asked for.
  • How much traceability is worth keeping, and how to keep it from going out of date.

By now the print-release service has requirements (FR-1 to FR-9, NFR-1 to NFR-5), assumptions (A1 to A8), acceptance criteria (AC-1.1 to AC-4.2), failure scenarios (F-1 to F-8), two examples, and about twenty tests. Three questions are hard to answer from any one of them:

  • Is every requirement checked by something?
  • If FR-4 changes, which code and which tests change?
  • Why does this function exist?

Each answer needs the links between them. Traceability is the practice of keeping those links where someone can read them.

“All 20 tests pass, so the requirements are met.”

Passing tests show that the behaviour they check works. They say nothing about the behaviour nobody wrote a test for. Without a link from each requirement to its tests, “all tests pass” and “a requirement is missing” can both be true. This page finds two such cases in the examples.

The earlier lessons gave everything an ID, and carried those IDs into the code:

  • Requirements have IDs and sources (the requirements lesson).
  • Each acceptance criterion belongs to a flow of a use case and names its requirements (the use-case lesson).
  • Each test’s name starts with its criterion’s ID, and its comment repeats the criterion.
  • Comments in the code name the requirement or assumption a line exists for:

VerifiedCompiled and tested with GNU 11.4.0 and Clang 14.0.0 (C++20, 2026-12-01).

release_station.cpp
// Use case UC-2: someone has badged in at this station's printer. Find out
// who they are, then go through their held jobs, oldest first, printing
// each one that fits their quota. Returns what happened to every job; never
// throws for an unknown badge or an empty queue.
ReleaseResult ReleaseStation::release(const BadgeId& badge) {
// Ask the badge system who this is. An empty optional means "unknown
// badge", and `!user` is true for an empty optional.
const std::optional<UserId> user = badges_.owner_of(badge);
// Early return: build a ReleaseResult from braces, outcome first and an
// empty list of jobs (`{}`) second. Nothing has been printed or changed.
if (!user) return {ReleaseOutcome::badge_not_recognised, {}};
// FR-8: only this user's jobs. FR-3: oldest first.
// *user reads the UserId out of the optional; it is safe because the
// check above has ruled out an empty one. `jobs` is a copy, so removing
// printed jobs from held_ below cannot disturb this loop.
const std::vector<PrintJob> jobs = held_.jobs_for(*user);
if (jobs.empty()) return {ReleaseOutcome::no_jobs_waiting, {}};
// A reference to the user's account inside quotas_, so try_charge
// below changes the real account, not a copy.
QuotaAccount& quota = quotas_.account_for(*user);
ReleaseResult result; // outcome starts as released, with no jobs yet
for (const PrintJob& job : jobs) {
// FR-4: each job is judged on its own. A job that does not fit is
// not printed and stays held (assumption A5, Q20).
// try_charge either takes all of the job's pages and returns true,
// or takes none and returns false; it never charges part of a job.
if (!quota.try_charge(pages_charged(job))) {
result.jobs.push_back({job.id, JobOutcome::over_quota});
// `continue` skips the rest of this pass and goes on to the next
// job, so a later, smaller job can still print.
continue;
}
// Here the pages are already charged: print, then stop holding it.
// remove's true/false answer is not needed: the job came from
// held_ moments ago, so it is there.
server_.print(printer_, job);
held_.remove(job.id);
result.jobs.push_back({job.id, JobOutcome::printed});
}
return result;
}

FR-8, FR-3, FR-4, and A5 appear in the code where they are implemented. A search for any of them finds the code, the criterion, and the test. That is traceability at its cheapest: no extra document, only a discipline about names.

A traceability table has one row per requirement, and columns for the design elements, the criteria, and the tests. Here it is for the print-release service, built from both examples. The last column is the point of the exercise.

Requirement Design elements Criteria / scenarios Tests Status
FR-1 hold, no print until released HeldJobs::hold; printing only from ReleaseStation::release AC-1.1 ac_1_1_… Tested
FR-2 release at any printer one ReleaseStation per printer; BadgeDirectory AC-2.1, AC-2.7 ac_2_1_…, ac_2_7_… Gap found and closed (below)
FR-3 at that printer, oldest first HeldJobs keeps submission order; station’s printer ID AC-2.1 ac_2_1_… Tested
FR-4 quota, panel says why QuotaAccount::try_charge, pages_charged, panel_text AC-2.4, AC-2.5 ac_2_4_…, ac_2_5_… Tested
FR-5 extra pages QuotaAccount::grant_extra, start_new_month AC-4.1, AC-4.2 ac_4_1_…, ac_4_2_… Tested
FR-6 set a user’s quota Quotas (the default of 500 only) none none Partly designed: the default exists; setting a user’s quota does not. “Could” in REQ-09, but now needed by the Q7 decision
FR-7 24-hour expiry HeldJobs::expire, hold_limit AC-3.1 ac_3_1_…; i6_… (failures example) Tested, but nothing calls expire on a timer yet
FR-8 owner only HeldJobs::jobs_for(owner); identity only from BadgeDirectory AC-2.6 ac_2_6_… Tested
FR-9 jam keeps the rest failures example: keep_unprinted, refund, print_one F-2, F-3 f2_… (three tests), f3_… Tested in the failures example, not yet in the main one
NFR-1 10 s for 95% a time limit on the badge lookup (not built) n/a none: checked by measuring Needs a measurement plan
NFR-2 2,000 held, 500 an hour a std::vector of held jobs, justified by the estimate none none Justified by estimate; a load test could check it
NFR-3 owner’s badge only as FR-8; fail closed on F-1 AC-2.2, AC-2.6, F-1 ac_2_2_…, ac_2_6_…, f1_… Tested
NFR-4 survive a restart none none none Not built; decided in REQ-09 (no names on disk)
NFR-5 change rules without a release none: values are constants none none Not met, and said so on REQ-04 and REQ-06

Assumptions get rows too, because a test that pins an assumption is the alarm that rings when it changes:

Assumption Design element Tests
A3 colour pages count the same pages_charged none directly (every quota test relies on it)
A5 a refused job stays held the continue in release ac_2_4_…, ac_4_1_…
A6 extra pages do not carry over QuotaAccount::start_new_month ac_4_2_…
A8 page counts are correct HeldJobs::hold rejects 0 pages ac_1_2_…

Reading it forwards: requirements with no test

Section titled “Reading it forwards: requirements with no test”

Read down the Tests column. Every empty cell is a requirement that nothing checks. They fall into four kinds, and each needs a different response:

  • Not designed yet (FR-6, NFR-4). Not a testing gap but a design gap. The table makes it visible; the priority decides when it is closed.
  • Not met (NFR-5). Recorded honestly, with the reason.
  • Checked another way (NFR-1, NFR-2). Some requirements are checked by measurement or by a load test, not by a unit test. The table should still name the check, or the requirement is effectively untested.
  • Tested too weakly. This is the one that needs a careful look, because the cell is not empty.

FR-2 says a user can release at any printer. When the table was first filled in, its only test was ac_2_1_…, which releases at 2-East, the one printer in the test fixture. The demonstration program uses two printers, but a demonstration is not a test. A design where every job printed at 2-East regardless of where the user stood would have passed every test.

The fix is small: a new criterion, AC-2.7 (“Given Robin holds a job, when Robin badges in at 3-West, then it prints at 3-West”), added to the use-case lesson’s table, and one test:

VerifiedCompiled and tested with GNU 11.4.0 and Clang 14.0.0 (C++20, 2026-12-01).

test_acceptance.cpp
// LLD_TEST(name) defines one test. LLD_CHECK(condition) records a failure
// if the condition is false; LLD_CHECK_EQ(actual, expected) does the same
// for `actual == expected` and prints both values when they differ; and
// LLD_CHECK_THROWS(expression, type) fails unless the expression throws
// that type of exception. A failed check does not stop the test: the
// remaining checks still run. They come from the site's small test header,
// lld_test.hpp.
// A fake badge system: the test fills `owners` with the badges it wants.
// `override` asks the compiler to confirm this really replaces the virtual
// function in BadgeDirectory. find returns an iterator to the matching
// entry, or owners.end() if there is none; found->second is the user ID.
class FakeBadges : public BadgeDirectory {
public:
std::map<BadgeId, UserId> owners;
std::optional<UserId> owner_of(const BadgeId& badge) const override {
const auto found = owners.find(badge);
if (found == owners.end()) return std::nullopt;
return found->second;
}
};
// Records what would have been printed, instead of printing it. A test
// can then compare `printed` with the list it expects, in order.
// emplace_back builds the (printer, job ID) pair straight in the vector.
class RecordingPrintServer : public PrintServer {
public:
std::vector<std::pair<PrinterId, int>> printed; // printer, job ID
void print(const PrinterId& printer, const PrintJob& job) override {
printed.emplace_back(printer, job.id);
}
};
// Everything one test needs, built fresh by `Office office;` in each test,
// so no test can see another's jobs or quotas.
// Members are built in order, so the station is built last and refers to
// the others; all are destroyed together at the end of each test.
struct Office {
FakeBadges badges;
RecordingPrintServer server;
HeldJobs held;
Quotas quotas{500};
ReleaseStation station{"2-East", badges, held, quotas, server};
Office() {
badges.owners = {{"B-01", "robin"}, {"B-02", "kim"}};
}
// `station` refers to the other members, so a copy would refer to the
// original's members.
Office(const Office&) = delete;
Office& operator=(const Office&) = delete;
// Leaves `pages` of this month's quota for the user by charging the
// rest of the 500: leave_quota("kim", 20) charges 480. The check fails
// the test if that charge is refused.
void leave_quota(const UserId& user, int pages) {
LLD_CHECK(quotas.account_for(user).try_charge(500 - pages));
}
};
const minutes nine = hours{9};
// AC-1.1 Given the print server reports a job, then it is held, nothing is
// printed, and it is listed for its owner only.
// Holds one job for robin, then proves the server printed nothing, robin's
// list has exactly that job, and kim's list is empty. `1u` is an unsigned
// 1, to match the unsigned type that size() returns.
LLD_TEST(ac_1_1_a_reported_job_is_held_not_printed) {
Office office;
const int id = office.held.hold("robin", "budget.xlsx", 12, nine);
LLD_CHECK(office.server.printed.empty());
const std::vector<PrintJob> robins = office.held.jobs_for("robin");
LLD_CHECK_EQ(robins.size(), 1u);
LLD_CHECK_EQ(robins.front().id, id);
LLD_CHECK(office.held.jobs_for("kim").empty());
}
// AC-1.2 (protects assumption A8) A job with no pages is rejected.
// Tries to hold a 0-page job: hold must throw std::invalid_argument, and
// count() must still be 0, so the bad job was not stored.
LLD_TEST(ac_1_2_a_job_with_no_pages_is_rejected) {
Office office;
LLD_CHECK_THROWS(office.held.hold("robin", "empty.pdf", 0, nine), std::invalid_argument);
LLD_CHECK_EQ(office.held.count(), 0);
}
// AC-2.1 Given a user with held jobs that fit their quota, when they badge
// in, then every job prints at this printer, oldest first, their quota
// goes down by the pages printed, and no job of theirs is still held.
// Robin holds a 12-page and then a 3-page job. Comparing the whole
// `printed` list proves both printed, at 2-East, in that order. 500 - 15 =
// 485 pages are left, and nothing of robin's is still held.
LLD_TEST(ac_2_1_badging_in_prints_all_held_jobs_oldest_first) {
Office office;
const int first = office.held.hold("robin", "budget.xlsx", 12, nine);
const int second = office.held.hold("robin", "minutes.docx", 3, nine + minutes{5});
const ReleaseResult result = office.station.release("B-01");
LLD_CHECK(result.outcome == ReleaseOutcome::released);
const std::vector<std::pair<PrinterId, int>> expected{{"2-East", first}, {"2-East", second}};
LLD_CHECK(office.server.printed == expected);
LLD_CHECK_EQ(office.quotas.account_for("robin").remaining(), 485);
LLD_CHECK(office.held.jobs_for("robin").empty());
}
// AC-2.2 Given a badge the badge system does not know, when it is used,
// then nothing prints and the panel says "Badge not recognised."
// B-17 is not in the fake directory. The outcome and the panel text say
// so, nothing printed, and robin's job is still held (count is 1).
// hold's returned ID is not needed here, so it is simply not stored.
LLD_TEST(ac_2_2_an_unknown_badge_prints_nothing) {
Office office;
office.held.hold("robin", "budget.xlsx", 12, nine);
const ReleaseResult result = office.station.release("B-17");
LLD_CHECK(result.outcome == ReleaseOutcome::badge_not_recognised);
LLD_CHECK_EQ(panel_text(result), std::string("Badge not recognised."));
LLD_CHECK(office.server.printed.empty());
LLD_CHECK_EQ(office.held.count(), 1);
}
// AC-2.3 Given a user with no held jobs, when they badge in, then the panel
// says "No jobs waiting."
// Robin's badge is known but nothing is held for robin.
LLD_TEST(ac_2_3_no_held_jobs_says_so) {
Office office;
const ReleaseResult result = office.station.release("B-01");
LLD_CHECK(result.outcome == ReleaseOutcome::no_jobs_waiting);
LLD_CHECK_EQ(panel_text(result), std::string("No jobs waiting."));
}
// AC-2.4 (assumption A5) Given a user with 20 pages of quota left, when they release a
// 30-page job, then it is not printed, it stays held, the quota is
// unchanged, and the panel says the quota is exceeded.
// Kim has 20 pages left and holds a 30-page job. The checks prove each
// part of the criterion: nothing printed, the job is still held, the
// quota is still 20 (try_charge changed nothing), the result names the job
// as over_quota, and the panel text gives the reason.
LLD_TEST(ac_2_4_a_job_over_quota_is_not_printed_and_stays_held) {
Office office;
office.leave_quota("kim", 20);
const int id = office.held.hold("kim", "contract.pdf", 30, nine);
const ReleaseResult result = office.station.release("B-02");
LLD_CHECK(office.server.printed.empty());
LLD_CHECK_EQ(office.held.jobs_for("kim").size(), 1u);
LLD_CHECK_EQ(office.quotas.account_for("kim").remaining(), 20);
LLD_CHECK_EQ(result.jobs.size(), 1u);
LLD_CHECK_EQ(result.jobs.front().job_id, id);
LLD_CHECK(result.jobs.front().outcome == JobOutcome::over_quota);
LLD_CHECK_EQ(panel_text(result),
std::string("Printing 0 job(s). 1 job(s) not printed: quota exceeded."));
}
// AC-2.5 (Q22) Given 20 pages left and held jobs of 30 then 5 pages, when the
// user badges in, then the 5-page job prints and the 30-page job stays held.
// The 30-page job comes first and does not fit; the loop goes on, so the
// 5-page job still prints. Only `small` was printed, only `big` is still
// held, and 20 - 5 = 15 pages are left.
LLD_TEST(ac_2_5_each_job_is_judged_on_its_own) {
Office office;
office.leave_quota("kim", 20);
const int big = office.held.hold("kim", "contract.pdf", 30, nine);
const int small = office.held.hold("kim", "memo.docx", 5, nine + minutes{2});
static_cast<void>(office.station.release("B-02"));
const std::vector<std::pair<PrinterId, int>> expected{{"2-East", small}};
LLD_CHECK(office.server.printed == expected);
const std::vector<PrintJob> still_held = office.held.jobs_for("kim");
LLD_CHECK_EQ(still_held.size(), 1u);
LLD_CHECK_EQ(still_held.front().id, big);
LLD_CHECK_EQ(office.quotas.account_for("kim").remaining(), 15);
}
// AC-2.6 Given two users with held jobs, when one badges in, then only that
// user's jobs print.
// Robin and kim both have a job held. After robin badges in, only robin's
// job printed and kim's is still held.
LLD_TEST(ac_2_6_only_the_badge_owners_jobs_print) {
Office office;
const int robins = office.held.hold("robin", "budget.xlsx", 12, nine);
office.held.hold("kim", "contract.pdf", 30, nine);
static_cast<void>(office.station.release("B-01"));
const std::vector<std::pair<PrinterId, int>> expected{{"2-East", robins}};
LLD_CHECK(office.server.printed == expected);
LLD_CHECK_EQ(office.held.jobs_for("kim").size(), 1u);
}
// AC-2.7 (added by the traceability check for FR-2) Given a user's held
// job, when they badge in at a different printer from the one in the other
// tests, then it prints at that printer.
// A second station, 3-West, shares the office's badges, held jobs,
// quotas, and server. Badging in there prints robin's job at 3-West, which
// proves the station sends jobs to its own printer, not a fixed one.
LLD_TEST(ac_2_7_jobs_print_at_whichever_printer_the_user_badges_in_at) {
Office office;
const int job = office.held.hold("robin", "budget.xlsx", 12, nine);
ReleaseStation west{"3-West", office.badges, office.held, office.quotas, office.server};
static_cast<void>(west.release("B-01"));
const std::vector<std::pair<PrinterId, int>> expected{{"3-West", job}};
LLD_CHECK(office.server.printed == expected);
}
// AC-3.1 Given a job held for 24 hours or more, when the expiry check runs,
// then it is deleted and can no longer be released; a job held for less
// than 24 hours is kept.
// old.pdf was held at 09:00, new.pdf at 09:01. At 09:00 the next day,
// old.pdf has waited exactly 24 hours, so it goes (the boundary case), and
// new.pdf, one minute short, stays. Badging in then prints only one job.
LLD_TEST(ac_3_1_jobs_held_24_hours_are_deleted) {
Office office;
office.held.hold("robin", "old.pdf", 4, nine);
office.held.hold("robin", "new.pdf", 2, nine + minutes{1});
LLD_CHECK_EQ(office.held.expire(nine + hours{24}), 1);
const std::vector<PrintJob> left = office.held.jobs_for("robin");
LLD_CHECK_EQ(left.size(), 1u);
LLD_CHECK_EQ(left.front().document, std::string("new.pdf"));
static_cast<void>(office.station.release("B-01"));
LLD_CHECK_EQ(office.server.printed.size(), 1u);
}
// AC-4.1 (assumption A5) Given a job refused for quota, when facilities grants enough extra
// pages and the user badges in again, then the job prints.
// Kim's 30-page job is refused with 20 pages left. 20 extra pages make
// 40, so the second badge-in prints it, leaving 40 - 30 = 10. The printed
// list has the job once: the first, refused attempt printed nothing.
LLD_TEST(ac_4_1_extra_pages_let_a_refused_job_print) {
Office office;
office.leave_quota("kim", 20);
const int id = office.held.hold("kim", "contract.pdf", 30, nine);
static_cast<void>(office.station.release("B-02"));
office.quotas.account_for("kim").grant_extra(20);
static_cast<void>(office.station.release("B-02"));
const std::vector<std::pair<PrinterId, int>> expected{{"2-East", id}};
LLD_CHECK(office.server.printed == expected);
LLD_CHECK_EQ(office.quotas.account_for("kim").remaining(), 10);
}
// AC-4.2 (assumption A6) Given extra pages granted this month, when a new
// month starts, then the user has the normal monthly quota only.
// Kim gets 50 extra pages and uses 40 (500 + 50 - 40 = 510 left). After
// start_new_month, used and extra are both reset, so exactly the normal 500
// is left: the 10 unused extra pages are gone.
LLD_TEST(ac_4_2_extra_pages_do_not_carry_into_the_next_month) {
Office office;
QuotaAccount& kim = office.quotas.account_for("kim");
kim.grant_extra(50);
LLD_CHECK(kim.try_charge(40));
kim.start_new_month();
LLD_CHECK_EQ(kim.remaining(), 500);
}

The new test is ac_2_7_jobs_print_at_whichever_printer_the_user_badges_in_at, near the end. Its comment says why it was added.

The general lesson: a test covers a requirement only if a design that broke the requirement would fail it. For each row, ask: what is the simplest wrong design that would pass these tests? If one exists, the coverage is weaker than the table suggests.

A gap between the code and the system: FR-7

Section titled “A gap between the code and the system: FR-7”

HeldJobs::expire is tested at the 24-hour edge. But nothing in either example calls it regularly. The function is right; the system around it does not yet use it. The table records it as a design gap: something must run the expiry check, for example once a minute. Unit tests cannot find this kind of gap; only reading the table against the whole design can.

Reading it backwards: code no requirement asks for

Section titled “Reading it backwards: code no requirement asks for”

Now read the other way. List the public parts of the design and find, for each, the requirement, flow, assumption, or constraint that justifies it:

Design element Justified by
HeldJobs::hold, remove FR-1
HeldJobs::jobs_for FR-3, FR-8
HeldJobs::expire FR-7
HeldJobs::count none: used only by tests and the demonstration
QuotaAccount::try_charge, remaining FR-4
QuotaAccount::grant_extra FR-5
QuotaAccount::start_new_month Q7 (a calendar month), A6
Quotas giving new users the default FR-6’s default of 500
BadgeDirectory, PrintServer C-2, C-1 (the boundary)
ReleaseOutcome::no_jobs_waiting UC-2 flow 3a
panel_text FR-4 (“the panel says why”), UC-2 step 6

Two observations:

  • A use-case flow is a valid justification. no_jobs_waiting has no FR, but it implements flow 3a, which was agreed with the stakeholders. The backward trace accepts requirements, flows, criteria, assumptions, and constraints, but not “it seemed useful”.
  • Support code is fine, if it is recognised as such. count exists for tests and output. That is a reasonable reason, but it is a different kind of reason. If it began to be used by the release logic, it would need a requirement.

Code with no justification at all is a question, not automatically a mistake: it might be a requirement nobody wrote down (add it), or a feature nobody asked for (remove it, or ask). Either way, it should not stay unexplained. Unrequested code has a cost: it must be tested, maintained, and secured, and it is often where unexpected behaviour comes from.

A traceability table that is updated by hand, separately from the code, goes out of date. Keep it cheap:

  • Put IDs where they are already maintained: test names, test comments, and code comments. A search reconstructs most of the table.
  • Check it mechanically where you can. Because every acceptance test is named after its criterion, a short script can list the criterion IDs in the use-case table and the test names in the code, and report any criterion with no test. (This site does not include such a script for the examples; it is an exercise in any language you like.)
  • Update it with each change. The prioritization lesson’s change check (record, list IDs, follow to tests) is a walk through this table.
  • Review the Status column at the moments the design commits further: before building a new part, before a release.
  • For a tiny program. A script with three requirements needs a sentence in the README, not a table.
  • As a substitute for thinking about coverage. A full table with weak tests is false confidence; FR-2 showed how.
  • Beyond what anyone reads. If the table is required by a regulator (for medical or aviation software, for example), it must be complete and formal. Otherwise, keep it at the level that helps answer real questions.

Traceability costs a little on every change: an ID in a test name, a comment, a row. It pays back when a requirement changes (the rework is found, not guessed), when a stakeholder asks “is X done?”, and when someone asks why a function exists. The cost rises steeply with granularity and with manual upkeep, so the cheapest form that answers those questions is the right one.

  • Counting tests instead of checking requirements. Twenty passing tests can leave a requirement unchecked.
  • Treating any test that mentions a requirement as coverage, as FR-2’s single-printer test showed.
  • Ignoring requirements that cannot be unit-tested, instead of naming the measurement that checks them.
  • Only tracing forwards. Code with no reason to exist is found only by tracing backwards.
  • A separate document nobody updates.

Facilities decides that FR-7’s 24 hours becomes 8 hours, to reduce how long confidential jobs wait.

Follow the FR-7 row: design element hold_limit (one constant; with NFR-5 met, it would be a setting instead), criterion AC-3.1, tests ac_3_1_… and the failures example’s i6_…. The criterion’s values change (8 hours and 7 hours 59 minutes), and so do both tests. The demonstration program’s expiry lines change too. Nothing else in the table mentions FR-7, so nothing else should change, and the rework estimate is a few lines plus their review.

Exercise: Fill the gaps in a traceability table

A meeting-room booking service has these requirements:

  • R-1 A user can book a free room for a time slot.
  • R-2 A room cannot be booked twice for overlapping times.
  • R-3 A user can cancel their own booking, up to its start time.
  • R-4 Only the person who booked, or an office administrator, can cancel a booking.
  • R-5 Bookings can be made at most 2 weeks ahead.

The design has a class BookingService with book, cancel, bookings_for(room, day), and export_to_csv. The tests are: books_a_free_room, refuses_an_overlapping_booking, refuses_a_booking_three_weeks_ahead, owner_can_cancel_before_start.

  1. Build the traceability table (requirement → design element → tests → status).
  2. Which requirements are untested, or tested too weakly? For each, write a test name.
  3. Which design element has no requirement? What would you do about it?
Show the explained answer

1. The table.

Requirement Design element Tests Status
R-1 book a free room book books_a_free_room Tested
R-2 no overlaps book (overlap check) refuses_an_overlapping_booking Tested, but weakly (see below)
R-3 cancel up to start cancel owner_can_cancel_before_start Half tested: nothing checks the refusal
R-4 who may cancel cancel (permission check) none Untested
R-5 2 weeks ahead book (window check) refuses_a_booking_three_weeks_ahead Tested, but not at the edge

2. Missing or weak tests.

  • R-4: another_user_cannot_cancel, administrator_can_cancel_any_booking. Security rules with no test are the most important gap here.
  • R-3: cannot_cancel_after_start. Only the allowed side is tested; a design that let anyone cancel at any time would pass.
  • R-2: which overlap does refuses_an_overlapping_booking test? Add refuses_a_booking_inside_another, refuses_a_booking_overlapping_the_end, and allows_a_booking_that_starts_when_another_ends (touching is not overlapping, which is an assumption to confirm).
  • R-5: allows_a_booking_exactly_two_weeks_ahead. Three weeks is far from the edge; a design with a 20-day limit would pass.

The question to ask for each row: what is the simplest wrong design that passes these tests?

3. Unjustified code. export_to_csv has no requirement. Ask who wanted it and why. If someone needs it (the office manager wants usage reports), write the requirement (R-6: the office manager can export a month’s bookings) and test it. If nobody does, remove it: it is code to maintain, and it exports who met whom, which may be a privacy question. bookings_for(room, day) has no requirement either, but it is plausibly needed for R-1 (to see which rooms are free); writing that down, as a requirement or as part of R-1, closes the gap.

  • Traceability links each requirement to its design elements and its tests. IDs in test names and code comments make most of the links free.
  • Read forwards to find requirements with no test: some are design gaps, some are checked by measurement, and some are tested too weakly.
  • A test covers a requirement only if a design that broke the requirement would fail it. Ask what the simplest wrong design is.
  • Read backwards to find code with no requirement. Either write the missing requirement, or question the code.
  • Trace at the level of functions and test names, keep IDs where they are already maintained, and update the table with each change.