Refactor duplicate test code.