Clean up duplication in unit test code