Improve test type detection, fix test run bug