For COVID-19, it is vital to understand if quarantines shorter than 14 days can be equally effective with judiciously deployed testing. Here, we develop a mathematical model that quantifies the probability of post-quarantine transmission incorporating testing into travel quarantine, quarantine of traced contacts with an unknown time of infection, and quarantine of cases with a known time of exposure. We find that testing on exit (or entry and exit) can reduce the duration of a 14-day quarantine by 50%, while testing on entry shortens quarantine by at most one day. In a real-world test of our theory applied to offshore oil rig employees, 47 positives were obtained with testing on entry and exit to quarantine, of which 16 had tested negative at entry; preventing an expected nine offshore transmission events that each could have led to outbreaks. We show that appropriately timed testing can make shorter quarantines effective.