TestSuite suite= new TestSuite();
suite.addTest(
new testCar("getWheels") {
protected void runTest() { testGetWheels(); }
}
);
suite.addTest(
new testCar("getSeats") {
protected void runTest() { testGetSeats(); }
}
);
return suite;
}
TestRunner
有了TestSuite我們就可以運行這些測試了,JUnit提供了三種界面來運行測試
[Text UI] junit.textui.TestRunner
[AWT UI] junit.awtui.TestRunner
[Swing UI] junit.swingui.TestRunner
我們前面已經看過文本界面了,下面讓我們來看一看圖形界面:
界面很簡單,鍵入類名-testCar;蛟趩覷I的時候鍵入類名:
[Windows] d:>java junit.swingui.TestRunner testCar
[Unix] % java junit.swingui.TestRunner testCar
從圖形UI可以更好的運行測試可查單測試結果。還有一個問題需要注意:如果JUnit報告了測試沒有成功,JUnit會區分失敗(failures)和錯誤(errors)。失敗是一個期望的被assert方法檢查到的結果。而錯誤則是意外的問題引起的,如ArrayIndexOutOfBoundsException。
文章來源于領測軟件測試網 http://www.kjueaiud.com/