单元测试
步骤:
1:导入jar包. //hamcrest-core-1.3.jar junit-4.12.
2:在对应方法上加上注解
注解:
@Test //表示测试该方法
@Before //在测试的方法前运行
@After //在测试的方法后运行
注意:
测试方法必须是"公共的,无返回值的,无参数的".
例子:
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestDemo {
@Before
public void aa(){
System.out.println("first");
}
@Test
public void add(){
int sum = 0;
for (int i = 0; i < 10