Added error handling for invalid tests