Wrap tests around the main loop logic