您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
如何使用JUnit做單元測試
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/3/21 10:27:10 ] 推薦標(biāo)簽:Junit 單元測試

  (二).測試類:

package com.tide.test;

import junit.framework.*;

import com.tide.prac.*;

public class TestCar extends TestCase {

private Car carObj;

protected void setUp() throws java.lang.Exception{

super.setUp();

if(carObj == null){

carObj = new Car();

}

}

protected void tearDown() throws java.lang.Exception{

super.tearDown();

carObj = null;

}

public static TestSuite suite() {

return new TestSuite(TestCar.class);

}

public static void main (String[] args) {

junit.textui.TestRunner.run(suite());

}

//以下是具體的測試代碼

public void testGetWheels(){

int wheelsExpect,wheelsActual;

wheelsExpect = 4;

wheelsActual = carObj.getWheels();

assertEquals(wheelsExpect,wheelsActual);

//下面是故意制造的錯(cuò)誤

wheelsExpect = 5;

wheelsActual = carObj.getWheels();

assertEquals(wheelsExpect,wheelsActual);

}

}

上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd