Refactor tests to remove duplication