Improved test handling