Improve error checking in a test