Assembly and publication of the severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2) genome in January 2020 enabled the immediate development of tests to detect the new virus. This began the largest global testing programme in history, in which hundreds of millions of individuals have been tested to date. The unprecedented scale of testing has driven innovation in the strategies, technologies and concepts that govern testing in public health. In this Review, we describe the changing role of testing during the COVID-19 pandemic, including the use of genomic surveillance to track SARS-CoV-2 transmission around the world, the use of contact tracing to contain disease outbreaks and testing for the presence of the virus circulating in the environment. Despite these efforts, widespread community transmission has become entrenched in many countries and has required the testing of populations to identify and isolate infected individuals, many of whom are asymptomatic. The diagnostic and epidemiological principles that underpin such population-scale testing are also considered, as are the high-throughput and point-of-care technologies that make testing feasible on a massive scale.