Courses / Testing in Research Workflows
Research code and data change throughout a project. New features, updated datasets, dependency changes and contributions from colleagues can introduce errors or silently alter results. Researchers already test their work informally by inspecting tables, plots and plausible value ranges, but these checks can be difficult to repeat consistently. Formal automated tests turn expectations about data, code and outputs into checks that can be rerun whenever a project changes. Combined with test coverage, continuous integration and defensive programming, they help researchers identify problems earlier, preserve intended behaviour and produce more trustworthy, reproducible analyses.
This practical course introduces testing for research workflows in Python and R. Using a small synthetic healthcare case study, participants learn how to write and run tests with pytest and testthat, parametrise repeated test cases, and use data in their tests. The course demonstrates smoke, unit, integration, system and regression tests. Participants also learn to interpret test coverage, automate testing with GitHub Actions, and use defensive programming to build checks and safeguards into their code. Examples and supporting code are available through the accompanying course website for participants to follow during the videos or revisit afterwards.
After completing this course, participants will be able to:
This course is intended for anyone who writes and maintains analytical code in Python or R and wants to make their work more reliable and reproducible. It introduces practical ways to automate checks on code, data and results, helping users identify problems early and have greater confidence in their analyses as projects develop or change.
The course assumes basic familiarity with functions, data frames and running code in either Python or R.
This course was developed as part of the project STARS: Sharing Tools and Artefacts for Reproducible and Reusable Simulations in healthcare. The STARS project is supported by the Medical Research Council [grant number MR/Z503915/1]. We are also supported by the National Institute for Health and Care Research (NIHR) under the NIHR Applied Research Collaboration South West Peninsula (Grant Reference Number NIHR200167). The views expressed are those of the author(s) and not necessarily those of the NIHR or the Department of Health and Social Care.
2 modules

Tom Monks
Associate Professor of Health Data Science in the Peninsula Collaboration for Health Operational Research and Data Science (PenCHORD)
View profile
Amy Heather
Postdoctoral Research Associate in the Peninsula Collaboration for Health Operational Research and Data Science (PenCHORD)
View profileHDR UK