Testing series

Tests for R code, R packages and Shiny apps

Tests for R code, R packages and Shiny apps, from a first testthat file to end-to-end Shiny tests in CI. Each post shows how a typical web project tests its code and how to do the same in R. The last post turns test results into evidence for regulated work. New posts are added as they’re written.

Parts in this series

7 parts WIP
#PartPublished
01
testthat essentials
Set up testthat 3rd edition, structure unit tests with expectations, run them locally and in CI, and build reproducible verification suites.
Published 2026-09-26
2026-09-26
02
Test design: fixtures, temporary state and mocking
Isolate test state with withr, manage fixtures cleanly in testthat 3e, and mock boundary functions to build repeatable verification suites.
Published 2026-09-26
2026-09-26
03
Snapshot tests for R output, tables and plots
Capture complex console output, rtables layouts, and plots with testthat snapshots and vdiffr to catch regressions without fragile manual assertions.
Published 2026-09-26
2026-09-26
04
Testing Shiny server logic with testServer()
Test Shiny modules and server logic headless with shiny::testServer(), verify reactive state and return values, and separate pure logic for testthat.
Published 2026-09-26
2026-09-26
05
End-to-end Shiny tests with shinytest2
Drive Shiny applications end to end with shinytest2 and headless Chrome, testing real browser rendering, user input sequences, and reactive outputs.
Published 2026-09-26
2026-09-26
06
Property-based testing in R
Define general invariants, generate varied test inputs with quickcheck, and use shrinking to pinpoint edge cases in R functions and clinical derivations.
Published 2026-09-26
2026-09-26
07
Coverage and tests as evidence
Use covr to spot untested paths, export Cobertura and JUnit XML in CI, and build automated requirement traceability matrices.
Published 2026-09-27
2026-09-27
More articles in this series are on the way.
No matching items