In many countries with organized cervical cancer screening, opportunistic Pap and human papillomavirus (HPV) tests are common. However, little is known about their effectiveness. We examined the effect of testing in and outside the Finnish screening program on the risk of cervical cancer. We conducted a case-control study that involved 1677 cases with invasive cervical cancer that were diagnosed between 2010 and 2019. Five- and three-year test intervals were analyzed across all ages, by age group and by cancer morphology subtype. Conditional logistic regression was used, adjusting for socioeconomic variables. Women undergoing any kind of cervical test had a significantly lowered risk of cervical cancer (adjusted OR = 0.43, 95% CI = 0.38–0.48, tests in five-year intervals). The results were similar, regardless of whether the test had been taken in the screening program or outside of it, or whether the interval was five years or three years. Testing of women at ages 35–64 showed the strongest effects, but moderate preventive effects were seen until age 79. No significant effect was seen below age 30. Tests in and outside the program were effective at the screening target age. However, participation in the program should be encouraged for optimal cost-effectiveness. Preventive effects were also seen above the program target ages.