(二).測試類:
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);
//下面是故意制造的錯誤
wheelsExpect = 5;
wheelsActual = carObj.getWheels();
assertEquals(wheelsExpect,wheelsActual);
}
}