(二).测试类:
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);
}
}