Junit是一个可编写重复测试的简单框架,是基于Xunit架构的单元测试框架的实例。Junit4最大的改进是大量使用注解(元数据),很多实际执行过程都在Junit的后台做完了,而且写test case 的类不需要继承TestCase,只需要在所要做test case的方法前加@Test 注解即可。

如:

1 import static org.junit.Assert.*;
2 2 public class TestCaculatorClass {
3 3     @Test
4 4     public void test() throws IOException, RuntimeException{
5 5         CaculatorClassForTest cal = new CaculatorClassForTest();
6 6         assertEquals(30, cal.sum(10, 20));
7 7     }
8 8 }
View @Test Code

相关文章: