Author-reviewedEvidence: highv1.0.1

Unit Testing

Unit testing checks each submodule or function of a health economic model on its own, comparing its output with expected results to find coding errors.

Status
Published, version 1.0.1
Last reviewed
12 Nov 2026, by Dr Darrin Baines
Report a problem
Tell us if something is wrong or out of date

Concept Architecture

Unit Testing of Health Economic Models

Unit testing means running one small piece of a health economic model by itself, such as a function that turns a rate into a probability or a block of cells that applies discounting, and checking that it returns an answer worked out beforehand. It is a technique of technical verification, which asks whether the model was built right, and it catches coding errors before they reach the ICER. The AdViSHE validation tool gives it its own item, C4, which asks whether individual sub-modules of the computerised model have been tested and whether a protocol describing the tests, criteria and acceptance norms was defined beforehand. The term comes from software testing, and Alarid-Escudero and colleagues describe a unit of code as often a function or a small process. It has nothing to do with unit costs.

A verification check on parts of the model

Sargent defines verification as ensuring that the computerised model's code and its implementation are correct, and keeps validation for whether the model is accurate enough for its intended use. Unit testing belongs on the verification side, since each test compares a part of the code with what its specification says the part should return. AdViSHE files it under Part C, validation of the computerised model, and Vemer and colleagues note that computerised model validity is sometimes called verification or technical validity.

The distinction limits what a passed test can show. Eddy and colleagues, for the ISPOR-SMDM task force, write that verification helps ensure there are no unintentional computational errors but does not evaluate the accuracy of the model's structure or predictions. A module that converts rates correctly can still be fed the wrong rate, a question for input data validation, and a correctly coded structure can still be the wrong structure, a question for conceptual model validation.

What counts as a unit in a decision model

In a model written in R or another language, the natural unit is a function. The DARTH coding framework of Alarid-Escudero and colleagues splits a decision model into core components common across cost-effectiveness analyses and HTA submissions, keeps the unit tests in a separate tests folder, and suggests one file of tests for each complicated function or component.

In a spreadsheet model the units are less obvious. The TECH-VER checklist organises verification by the compartmentalised modules of a typical decision model, namely input, event and state, result and uncertainty analysis calculations, although it never uses the term unit testing. AdViSHE item C4 lists examples, such as turning sub-modules on and off and testing warning messages, switches, formulas and macros.

How a unit test is written and run

A unit test feeds chosen inputs to one unit and compares its output with an expected value within a stated tolerance. Alarid-Escudero and colleagues say a single function will usually have several tests, checking that it runs when inputs are of the right data type, that its outputs are of the right type, and that they are correct in dimension and value for specific inputs. The function's own error checking should also be tested, so that it returns an error when given invalid inputs.

The DARTH authors also suggest a new test whenever a bug is found. AdViSHE asks for criteria and acceptance norms set before testing begins, and Balci's principles state that tests should be identified, prepared, scheduled and documented, because ad hoc testing does not give a reasonable measure of model accuracy. Hamilton and colleagues separate unit tests, which run small isolated sections of code on their own, from acceptance tests, which run several components together.

Who does it and what gets reported

The DARTH authors expect developers to write unit tests as they build, whereas Balci's simulation framework leaves the modeller only informal private testing and gives formal submodel (module) testing, which treats each submodel as a stand-alone unit, to an independent simulation quality assurance group. AdViSHE asks where the tests and their outcomes are reported, or why no unit testing was done. NICE PMG36 (2022, updated 2026), section 4.6.4, asks companies to detail the methods of quality assurance used in developing the model and to provide the methods and results of model validation, which is where a unit test record belongs. A reviewer such as an External Assessment Group can then judge whether the tests cover the calculations that drive the result.

In a review of 78 model-based evaluations in early breast cancer published between 2016 and 2024, Abraham and colleagues found validation of the computerised model, the AdViSHE category that holds unit testing, reported in under 4% of studies. One published AdViSHE report, for the PRIMEtime CE model, describes unit testing as the separate analysis of model submodules.

Worked example with three units of a Markov cohort model

All numbers are illustrative except the discount rate. A Markov cohort model with annual cycles has three units written as functions, and the test protocol sets a tolerance of 0.0001 for every numerical test. The first unit converts a constant annual event rate into a cycle transition probability.

p=1−e−rtp = 1 - e^{-r t}

where pp is the probability of the event within the cycle, rr is the constant event rate per year, and tt is the cycle length in years.

The second unit builds each row of the transition matrix from the probabilities of leaving a state, and the third unit returns the discounting factor for a cycle.

Dk=1(1+d)kD_k = \frac{1}{(1 + d)^{k}}

where DkD_k is the discount factor applied to costs or QALYs accrued in a cycle, dd is the annual discount rate, and kk is the number of whole years elapsed, so the first cycle has kk equal to 0, the timing this model specifies. The protocol uses dd equal to 3.5%, the reference-case rate for costs and health effects in NICE PMG36 section 4.5.1.

UnitTest inputExpected outputFirst version returnsResult
Rate to probabilityRate 0, cycle 1 year00Pass
Rate to probabilityRate 0.10, cycle 1 year0.09520.1000Fail
Rate to probabilityRate minus 0.10Error messageminus 0.1000Fail
Matrix row for WellDeath 0.0952, progression 0.2000Stay 0.7048, row sum 1Stay 0.7048, row sum 1Pass
Discount factorYear 01.00000.9662Fail
Discount factorYear 100.70890.6849Fail

1. Rate to probability. For a rate of 0.10, e−0.10e^{-0.10} is 0.9048, so pp is 1 minus 0.9048, or 0.0952. The first version uses the rate as if it were a probability and returns 0.1000, a gap of 0.0048, above the tolerance, and it accepts a negative rate without complaint. The zero-rate test passes for both versions, which is why test values need ordinary as well as edge inputs.

2. Transition matrix row. From the Well state the probability of staying is 1 minus 0.0952 minus 0.2000, which is 0.7048, and the row sums to 1.

3. Discount factor. At kk equal to 10 the specified factor is 1 divided by 1.035 to the power 10, which is 0.7089. The first version starts counting at 1, so it returns 1 divided by 1.035, or 0.9662, for the first cycle and 0.6849 at kk equal to 10. Both tests fail and the analyst fixes the unit.

4. What the unit tests cannot see. After the fixes all three units pass, but the cost calculation passes the cycle number, which starts at 1, to the discount function instead of the years elapsed. A first-year cost of GBP 1,000 is therefore reported as 1,000 divided by 1.035, or GBP 966.18. The fault lies in how two correct units are joined, so none of the three unit tests can find it. A test of the joined units, which Balci calls integration testing, or a check on the assembled model such as black-box testing or a hand calculation of the first cycle, will find it.

Neighbouring checks and other names

Unit testing is named for its scope, one part at a time, whereas black-box and white-box testing are named for their method, watching how outputs respond to inputs or reading formulas or code line by line, so a unit test is in effect a black-box test of one part. Integration testing and system testing check that the parts work together and that the whole model gives sensible results, the role Hamilton and colleagues give to acceptance tests, automated developer tests that differ from Model Acceptance Testing, the sponsor's final check before it relies on a model. Regression testing reruns earlier tests after a change, which a stored unit test suite makes quick, and double programming rebuilds a calculation independently. Component testing, module testing and Balci's submodel testing name the same idea.

Limits of testing the parts

Balci states that successfully testing each submodel does not imply overall model credibility, because errors allowed in each submodel may accumulate to an unacceptable level for the whole model, so the whole model must still be tested. He also notes that complete testing under all possible inputs is not possible, so a test suite raises confidence without proving correctness. A unit test is only as good as its expected value, and an analyst who derives that value from the same misreading of the specification will write a test that passes a wrong unit. Some models are not built from separable parts, as the PRIMEtime CE report says of how that model estimates effects on health, and even purpose-built R frameworks can fall short, as Hamilton and colleagues report only limited use of unit testing in their own module libraries. Unit tests therefore support model validation as one part of a wider verification record, and do not replace checks on the assembled model and its structure.

Sources

  • Abraham K, Corro Ramos I, Braal CL, Feenstra T, Kleijburg A, van Voorn GAK, Uyl-de Groot C. Under-reporting of validation efforts for health economic models persists despite the availability of validation tools: a systematic review. PharmacoEconomics. 2025;43:849-858. https://doi.org/10.1007/s40273-025-01491-2
  • Alarid-Escudero F, Krijkamp EM, Pechlivanoglou P, Jalal H, Kao SYZ, Yang A, Enns EA. A need for change! A coding framework for improving transparency in decision modeling. PharmacoEconomics. 2019;37(11):1329-1339. https://doi.org/10.1007/s40273-019-00837-x
  • Balci O. Principles and techniques of simulation validation, verification, and testing. In: Proceedings of the 1995 Winter Simulation Conference. 1995:147-154. https://www.informs-sim.org/wsc95papers/1995_0021.pdf
  • Balci O. Verification, validation, and testing. In: Banks J, ed. Handbook of Simulation. New York: John Wiley & Sons; 1998:335-393. https://doi.org/10.1002/9780470172445.ch10
  • Briggs ADM, Wolstenholme J, Scarborough P. Estimating the cost-effectiveness of salt reformulation and increasing access to leisure centres in England, with PRIMEtime CE model validation using the AdViSHE tool. BMC Health Services Research. 2019;19:489. https://doi.org/10.1186/s12913-019-4292-x
  • Büyükkaramikli NC, Rutten-van Mölken MPMH, Severens JL, Al M. TECH-VER: a verification checklist to reduce errors in models and improve their credibility. PharmacoEconomics. 2019;37(11):1391-1408. https://doi.org/10.1007/s40273-019-00844-y
  • Eddy DM, Hollingworth W, Caro JJ, Tsevat J, McDonald KM, Wong JB. Model transparency and validation: a report of the ISPOR-SMDM Modeling Good Research Practices Task Force-7. Value in Health. 2012;15(6):843-850. https://doi.org/10.1016/j.jval.2012.04.012
  • Hamilton MP, Gao C, Wiesner G, Filia KM, Menssink JM, Plencnerova P, et al. A prototype software framework for transferable computational health economic models and its early application in youth mental health. PharmacoEconomics. 2024;42(8):833-842. https://doi.org/10.1007/s40273-024-01378-8
  • National Institute for Health and Care Excellence. NICE technology appraisal and highly specialised technologies guidance: the manual (PMG36). Published 31 January 2022, last updated 13 October 2026. Sections 4.5.1 and 4.6.4. https://www.nice.org.uk/process/pmg36
  • Sargent RG. Verification and validation of simulation models. In: Proceedings of the 2011 Winter Simulation Conference. 2011:183-198. https://www.informs-sim.org/wsc11papers/016.pdf
  • Vemer P, Corro Ramos I, van Voorn GAK, Al MJ, Feenstra TL. AdViSHE: a validation-assessment tool of health-economic models for decision makers and model users. PharmacoEconomics. 2016;34(4):349-361. https://doi.org/10.1007/s40273-015-0327-2

Library

Publications

1
  • Journal article

    Modeling Good Research Practices — Overview: A Report of the ISPOR-SMDM Modeling Good Research Practices Task Force-1 — Caro, Briggs, Siebert & Kuntz, Task Force Report 1 ed., 2012 (Value in Health / Medical Decision Making)

    The overview paper of the seven-part ISPOR-SMDM modelling good-practice series, setting out best-practice recommendations across model design, technique selection, implementation, validation, parameterisation, uncertainty and use in decision making.

Frequently Asked Questions (6)

  • What is unit testing?

    Unit testing checks each submodule or function of a health economic model on its own, comparing its output with expected results to find coding errors.

    Source: Vemer et al. 2016

  • Why test model components in isolation before combining them?

    Testing each part of a health economic model on its own means a failed unit test points to one function or block of cells, whereas a wrong result from the combined model could come from anywhere. Balci's simulation testing framework puts submodel testing before integration testing, treating each submodel as a stand-alone unit with its own inputs and outputs. Integration testing can then concentrate on the interfaces between parts. In an illustrative model, a function that applies a hazard ratio of 0.5 by halving a death probability of 0.40 returns 0.2000 instead of 0.2254 and fails its own test at once, but in the full model it only shifts the QALY gain by a plausible-looking amount.

    Source: Balci 1998

  • How is unit testing carried out?

    Each test feeds chosen inputs to one function or block and checks the output against an expected value within a stated tolerance. Alarid-Escudero and colleagues expect several tests per function, covering whether it runs with inputs of the right data type, whether its outputs have the right type, and whether they are correct in dimension and value for given inputs. Tests should also confirm that the function returns an error for invalid inputs, such as a negative rate. In their DARTH framework the tests sit in a separate folder, with one file for each complicated function or component, and a new test is added whenever a bug is found.

    Source: Alarid-Escudero et al. 2019

  • Why is unit testing useful?

    Unit testing finds coding errors close to where they are made, before they reach the ICER. In an illustrative Markov model, a function that uses an annual rate of 0.10 as if it were a probability returns 0.1000 instead of 0.0952, a slip that a single test exposes at once. A stored set of tests can also be rerun quickly after every change to the model. For a NICE appraisal, PMG36 (2022, updated 2026) section 4.6.4 asks companies for their quality assurance methods and validation results, so a test record lets the External Assessment Group judge whether the calculations that drive the result were checked.

    Source: NICE PMG36 (2022, updated 2026)

  • How does unit testing differ from system testing?

    Unit testing checks one part of a health economic model in isolation, while system testing checks that the assembled model works as a whole and gives sensible results. Balci warns that passing every submodel test does not make the whole model credible, because small errors allowed in each part can add up to an unacceptable error overall, so the whole model must still be tested. Faults can also sit in the joins between correct parts. A cost calculation that passes the cycle number to a correct discount function, instead of the years elapsed, discounts the first year wrongly and is missed by tests of each part alone. It shows up only when the joined parts are tested together.

    Source: Balci 1998

  • How does unit testing relate to model verification?

    Unit testing is one technique of model verification, the check that a health economic model was built as intended. Eddy and colleagues, for the ISPOR-SMDM task force, list verification of separate parts of a model one by one among checks on coding accuracy, and write that verification helps ensure there are no unintentional computational errors but does not evaluate the accuracy of the model's structure or predictions. A function that converts rates correctly can still be given the wrong rate, which is a matter for input data validation. An External Assessment Group that finds a full record of unit tests in a company submission still needs to examine the model's inputs and structure on their own terms.

    Source: Eddy et al. 2012

Trust Record

Verified by Dr Darrin Baines

British health economist

Professional identity: darrinbaines.org

Verification date: 12 Nov 2026

Content version: 1.0.1

Canonical Identity

Term code
HE-EM-MV-087

Stable URI · Machine-readable · Resolvable · CC BY 4.0

This article is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).

Author: Dr Darrin Baines · Publisher: Intelligent Parameters Ltd · Identifier: https://healtheconomics.wiki/concept/unit-testing