Improve test error handling