Documentation

D.10 The test layers: unit, end-to-end and independent

Three layers of tests

What you will learn

  • Name the layers of testing and what each can and cannot catch.
  • Decide which layer a new test belongs to.
  • Explain why the program's own tests are not the same as its validation package.

Prerequisites: D.5 and Chapter 42, validation and testing.

Four layers

Layer What it checks Where it lives Size (order of magnitude)
1. Unit tests a function or a module on small, constructed inputs beside the code, in the module they test more than 500
2. End-to-end tests the program as a user runs it: the real executable, real files, the exit code, the files written one end-to-end test file about 170
3. Independent QC the numerical answers of selected commands against a separate implementation (a simulator written in another language) the QC folder (scripts for autoinit, screen and the target-mediated models, and one for nca) a handful of scripted scenarios
4. The validation package the program against written requirements, risks and tests, with evidence, for use in a regulated setting kept and versioned separately from the program 90 requirements, 42 risks, 118 tests (Chapter 42)

The first two are the maintainer's daily tools and run on every change. The third was built to answer "is the number right?" with an independent calculator, and runs when numerical code changes. The fourth is the book's subject in Chapter 42, and is a different activity: it produces evidence for a user's quality system, and it is not part of the development loop.

What each layer is good for

Question Layer
Does this function handle an empty list, a NaN, a boundary? unit
Does a dataset with a decreasing time within an individual give check TIM01? unit (the check on a small in-memory table)
Does nlmx qc-data on a defective file exit with 7 and write the checklist? end-to-end
Does a misspelled settings key give exit code 4 and name the key? end-to-end
Is the estimate of clearance from autoinit within tolerance of the true value of a simulated dataset? independent QC
Is the whole installed program qualified for a given use? validation package

Where unit tests stop

A unit test sees only what its author put in front of it. It cannot see that a command forgot to write a file, that the exit code is wrong, that the help omits an option, or that two modules disagree about a column name, because those only happen when the whole program runs. That is why every user-visible behaviour has an end-to-end test, and unit tests are for the logic underneath.

Where end-to-end tests stop

They are slow (the whole suite takes minutes, not seconds), so they use small examples: the example project generated once per run, and smaller projects of other model kinds. They show that the program does what its author expected, and the expectations may be wrong. That is the reason for layer 3: a second implementation, written separately, that disagrees loudly when the program's numbers are off.

Independent QC

The QC folder holds scripts that simulate data with their own code (a simulator that shares no code with the program, itself checked against closed-form solutions), run the program on it, and compare the result with the known truth within stated tolerances: initial estimates from simulated one-, two- and three-compartment data of several designs (intravenous bolus and infusion, oral with lag, sparse sampling, steady state, crossover), structural screening, and the target-mediated models. Its README records the scenarios and the tolerances. It needs a scripting environment with numerical libraries, and is not part of the build. It is deliberately small and deliberately independent: sharing code with the program would defeat it.

The validation package is not the test suite

It is tempting to say "the tests pass, so it is validated". They are different things.

Test suite Validation package
Purpose find defects during development demonstrate fitness for a stated use
Audience maintainers quality units, auditors
Traceability to code requirements to risks to tests to evidence
When run every change at release and installation
Result pass/fail a signed report

The development tests give confidence that the package will pass; they do not replace it.

Deciding where a test belongs

  1. If it needs only a function and constructed values: unit.
  2. If it concerns what a user sees (an option, an exit code, a file, a message): end-to-end.
  3. If it concerns whether a number is true and the program computes it a hard way: independent QC, or a hand check in the guide.
  4. If it concerns a requirement a regulator would ask about: it belongs in the validation package, with its trace.

Review checklist

  • Does every user-visible behaviour in the change have an end-to-end test?
  • Is the logic underneath covered by unit tests on constructed inputs?
  • If numerical code changed, was the independent QC re-run?
  • Is the change recorded for the validation package if it touches a requirement?

See the previous page, the next page and the developer reference.