Refactor error-case unit tests to remove duplication