Rewrite tests to use a loop