Refactor test code to be more reusable.