jUnit4 概述 jUnit4 是 JUnit 框架有史以来的最大改进,其主要目标便是利用Java5 的 Annotation 特性简化测试用例的编写
先简单解释一下什么是Annotation,这个单词一般是翻译成元数据
元数据是什么
元数据就是描述数据的数据
也就是说,这个东西在Java 里面可以用来和public、 static 等关键字一样来修饰类名、方法名、变量名
修饰的作用描述这个数据是做什么用的,差不多和public描述这个数据是公有的一样
想具体了解可以看Core Java2
废话不多说了,直接进入正题
我们先看一下在JUnit 3 中我们是怎样写一个单元测试的
比如下面一个类: public class AddOperation { public int add(int x,int y){ return x+y; } } 我们要测试add 这个方法,我们写单元测试得这么写: import junit
framework
TestCase; import static org
Assert
*; public class AddOperationTest extends TestCase{ public void setUp() throws Exception { } public void tearDown() throws Exception { } public void testAdd() { System
println(\"add\"); int x = 0; int y = 0; AddOperation instance = new AddOperation(); int expResult = 0; int result = instance
add(x, y); assertEquals(expResult, r