Junit4生命周期

package junit.util;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class JunitFlowTest {
/**
* @BeforeClass:这个注解表示这个方法会在所有测试方法执行之前执行
* 因为是static修饰的静态方法,所有只会执行一次。通常用来进行一些
* 资源的加载,如通过JUnit测试Spring相关的东西时,可以在这个方法
* 中加载Spring的配置文件
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.println(“this is before class”);
}

/**
 * @AfterClass:这个注解表示这个方法会在所有方法执行完毕之后执行,通常用来释放资源
 */
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println("this is after class");
}

/**
 * @Before:这个注解表示这个方法会在每个测试方法执行之前执行一次
 * 有多少个测试方法就会执行多少次
 */
@Before
public void setUp() throws Exception {
System.out.println("this is before");
}

/**
 * @After:这个注解表示这个方法会在每个测试方法执行之后执行一次
 * 有多少个测试方法就会执行多少次
 */
@After
public void tearDown() throws Exception {
System.out.println("this is Down");
}

@Test
public void test1() {
System.out.println("this is test1");
}

@Test
public void test2() {
System.out.println("this is test2");
}

}

/* outPut:
this is before class
this is before
this is test1
this is Down
this is before
this is test2
this is Down
this is after class
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值