Factor out common test code