标签:
1、在编写的类上右击鼠标,选择new在选择JUnit Test Case后出现下图
然后按图填写必要信息
2、点击Next按钮得到如下图示然后在选择部分测试的方法
点击Finish这样我们的JUnit测试实例就建好了。然后就可以写具体的测试方法了
写好以后,右击该类选择Run “JUnit Test”,出现下图代表测试通过:
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class RectTest {
private static Rect rect = new Rect();
@Before
public void setUp() throws Exception {
}
@Test
public void testGetwidth() {
rect.setwidth( 20) ;
if (rect.getwidth()<=0)
fail("Not yet implemented");
else equals( rect.getwidth());
}
@Test
public void testGetheight() {
rect.setheight(-20);
if (rect.getheight()<=0)
fail("Not yet implemented");
else equals( rect.getheight());
}
@Test
public void testArea() {
rect.setwidth(10);
rect.setheight(20);
if(rect.getwidth()<=0||rect.getheight()<=0)
fail("Not yet implemented");
else equals( rect.area());
}
}
标签:
原文地址:http://www.cnblogs.com/joanjoan/p/5862071.html