Refactor test helpers