通過前面的介紹,我們對JUnit有了一個大概的輪廓。知道了它是干什么的,F在讓我們動手改寫上面的測試類testCar使其符合Junit的規范--能在JUnit中運行。
//執行測試的類(JUnit版)
import junit.framework.*;
public class testCar extends TestCase {
protected int expectedWheels;
protected Car myCar;
public testCar(String name) {
super(name);
}
protected void setUp() {
expectedWheels = 4;
myCar = new Car();
}
public static Test suite() {
/*
* the type safe way
*
TestSuite suite= new TestSuite();
suite.addTest(
new testCar("Car.getWheels") {
protected void runTest() { testGetWheels(); }
}
);
文章來源于領測軟件測試網 http://www.kjueaiud.com/