JUnit初学

package com.junit.test;
import static org.junit.Assert.*; //注意这里是静态引入了类里的方法
import org.junit.Test;
public class TTest {
@Test
public void testAdd() {
fail(
"Not yet implemented");
}
}

  静态引入:可以不加类名直接引入类里的方法,比如fail方法,不用写成Assert.fail


1.       @Test: 测试方法

    a)        (expected=XXException.class)

    b)        (timeout=xxx)

2.        @Ignore: 被忽略的测试方法

3.        @Before: 每一个测试方法之前运行

4.        @After: 每一个测试方法之后运行

5.        @BeforeClass: 所有测试开始之前运行

         public static void setUpClass() throws Exception {   //这里必须是静态方法
             // one-time initialization code
         }

6.        @AfterClass: 所有测试结束之后运行


@BeforeClass: 用在需要搭建比较复杂的环境(如连接数据库)或者需要取得一些很耗费时间的资源。

@AfterClass: 需要卸载环境或者释放资源的时候

原文地址:https://www.cnblogs.com/clara/p/2173244.html