9.2.2. Misuse Case Testing and Coverage Analysis
💡 First Principle: Scanners test what code does wrong in general; misuse cases test what this application must never allow; coverage analysis tells you how much of the code and the requirements your tests actually exercised. The first two find flaws, the third measures the evidence behind "we tested it". The reusable questions: which abuses of this business process would hurt most, is there a test that attempts each one, and which code did no test ever run?
Misuse-case testing for business logic: business-logic flaws (negative quantities, skipped workflow steps, a discount applied twice, price or quantity tampering, reading another customer's record by changing an ID) match no SAST pattern, no SCA advisory and no scanner signature, and an unauthenticated scan never reaches the workflow. They are found by authenticated dynamic or manual tests built from misuse cases, the abuse cases written during requirements (9.1.1). Each misuse case becomes a negative test: perform the steps out of order, replay a request, submit a value the interface would never send, run two requests at once, act as a different user. The expected result is a refusal, and the test passes only if the refusal happens on the server. Once written, the test joins the automated regression suite so a later change cannot quietly reopen the flaw.
Coverage analysis: coverage is measured by instrumenting the code and recording what executes while the tests run. The common measures, from weakest to strongest:
| Measure | Question it answers | Gap it leaves |
|---|---|---|
| Function coverage | Was every function called at least once? | Says nothing about what happens inside it |
| Statement (line) coverage | Did every statement execute? | An if with no else can be fully covered without ever testing the false case |
| Branch (decision) coverage | Did every decision take both its true and false outcome? | A compound condition can pass without each part being tested |
| Condition coverage | Did each individual condition evaluate both true and false? | Does not show each condition affecting the outcome |
| Loop coverage | Did each loop run zero, one and many times? | Boundary values inside the loop |
| Path coverage | Did every route through the code execute? | Rarely achievable: loops and branches multiply the paths |
Safety-critical software pushes further: DO-178C requires modified condition/decision coverage (MC/DC), showing that each condition independently affects the decision, for the most critical level of airborne software. Coverage can also be measured against requirements rather than code: the share of use cases and misuse cases that have at least one test (tested cases divided by total cases), tracked in a traceability matrix.
Reading coverage as a manager: coverage shows what ran, not what was checked. A test with no meaningful assertion still produces coverage, and 100% line coverage of an authorization function proves nothing if no test ever called it as the wrong user. Use coverage to find the untested code, especially security-critical paths such as authorization checks, input parsing and error handlers, and set targets per component rather than one number for the whole codebase. Coverage-guided fuzzers use the same instrumentation to steer their inputs toward code not yet reached.
⚠️ Exam Trap: "The application has 95% code coverage, so it has been thoroughly tested." Coverage measures execution, not correctness or security. Statement coverage can be complete while every false branch, every error path and every misuse case goes untested. When asked how to judge test adequacy, prefer stronger measures (branch or condition coverage), coverage of security-critical code, and requirements coverage that includes misuse cases.
Reflection Question: An online retailer's checkout passes SAST, DAST and SCA with no high findings and reports 88% line coverage. A customer discovers that applying a coupon, removing the item and adding it back applies the discount twice. Why did none of the tools or the coverage figure reveal this, which misuse cases would you add to the test suite, and which coverage measure would you ask for on the pricing and authorization code?