Cost Optimizations In Runtime Testing And Diagnosis