Refactored common test code.