Add test helpers and rewrite tests