In the early stages of the COVID-19 pandemic, PCR testing served different purposes for individuals and for policy makers. Policy makers relied on testing for representative case numbers to track and mitigate the spread of the disease whereas individuals needed tests to protect themselves and others, or to travel or go work. Systematic differences in testing across population groups can bias case numbers, making it more difficult for policy makers to implement effective non-pharmaceutical interventions. We link records of 494 699 PCR-tests taken between 2020-07-01 and 2020-12-31 to individual records in several administrative registers for 1 480 126 working age individuals in the counties of Stockholm and Scania in Sweden. We estimate the likelihood of getting tested, test positivity rate and hospitalization risk by sex, household size, migration background, education, income and medical risk factors in the individual or in the household using regression models with age, occupation and neighbourhood as fixed effects. We find that testing behaviour vary independently by several demographic, socioeconomic and medical factors. Several groups that were at an elevated risk of being hospitalized for COVID-19, including men, individuals born outside Europe and those with low education, had low testing rates and high positivity rates. Numbers of confirmed SARS-CoV-2 infections reflect both infection rates and the testing behaviour of the population. To improve the utility of testing in future pandemics, policy makers may collect data on negative tests and dedicate part of the testing capacity for representative screening.