2. 下面介绍junit4 的常用注解
* @ Test:测试方法
A) (expected=XXEception.class)
B) (timeout=xxx)
*. @ Ignore:被忽略的测试方法
*. @Before:每一个测试方法之前云行。
*. @After :每一个测试方法之后运行。
*. @BefreClass所有测试开始之前运行。
*. @AfterClass所有测试结果之后运行。
下面通过一个测试程序来解释这些注解含义
packagecom.junit4.cc.test;
importstaticorg.junit.Assert.*;
importstaticorg.hamcrest.Matcher.*;
importorg.junit.Test;
importcom.junit4.cc.*;
importorg.junit.Before;
importorg.junit.BeforeClass;
importorg.junit.AfterClass;
importorg.junit.After;
importorg.junit.Ignore;
publicclassTTest {
@BeforeClass//的所有方法运行之前运行。
publicstaticvoidbeforeClass(){
System.out.println("------------beforeClass");
}
@AfterClass//在所有方法运行之后运行
publicstaticvoidafterClass(){
System.out.println("-------------afterClass");
}
@Before//每个测试方法运行之前运行
publicvoidbefore(){
System.out.println("=======before");
}
@After//每个测试方法运行之后运行
publicvoidafter(){
System.out.println("=======after");
}
@Test
publicvoidtestAdd() {
intz=newT().add(5,3);
assertEquals(8,z);
System.out.println("test Run through");
}
@Test ()
publicvoidtestdivision(){
System.out.println("in Test Division");
}