JUnit单元测试

时间:2014-11-26 01:13:38   收藏:0   阅读:150
 1 import org.junit.Test;
 2 public class TestPerson{
 3     
 4     @Test
 5     public void TestRun(){
 6         Person p = new Person();
 7         p.run();
 8     }
 9     
10     @Test
11     public void TestEat(){
12         Person p = new Person();
13         p.eat();
14     }
15 }        

针对每个类的每个方法编写独立的测试码,@Test相当于提供一个独立的程序入口而不必使用main函数。

当然除了@Test还有一些常用的,如@before和@after

@before会在测试码中任意方法之前运行,可以在其中加上需要初始化的资源;
@after会在任意方法之后运行,可以在其中加上需要释放的资源。
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!