Refactor an error testing method.