public class AnnotationTest {
/*
* @Test:将普通方法修饰为测试方法
* expected=***.class:设定抛出的异常
* timeout=***(毫秒):避免测试时候出现死循环问题
* @BeforClass:它会在所有方法运行前执行,static修饰
* @AfterClass:它会在所有方法运行后执行,static修饰
* @Before:会在每一个测试方法执行前运行
* @After:会在每一个测试方法执行后运行
* @Ignore:该方法并不会被执行,会被测试运行器忽略
* @RunWith:可以更改测试运行器(自定义测试运行器要继承org.junit.runner.Runner)
* */
@Test(expected=ArithmeticException.class,timeout=1000) //预期抛出算数异常,单元测试通过
public void test1(){
assertEquals(1, new Caculate().Chu(3, 0));
}
@Ignore
@Test(timeout=1000) //1000毫秒控制运行
public void test2() throws InterruptedException{
Thread.sleep(500);
}
}
Junit4常用注解
最新推荐文章于 2024-08-12 08:00:00 发布