JUnit中@BeforeClass@AfterClass@Before@After和@Test
2016-05-18 15:47
531 查看
1.@BeforeClass修饰的方法会在所有方法被调用前被执行,而且该方法是静态的,所以当测试类被加载后接着就会运行它,
而且在内存中它只会存在一份实例,它比较适合加载配置文件。
2.@AfterClass所修饰的方法通常用来对资源的清理,如关闭数据库的连接
3.@Before和@After会在每个测试方法的前后各执行一次。
package com.cyt;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class JunitFlowTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.println("this is beforeClass...");
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println("this is afterClass...");
}
@Before
public void setUp() throws Exception {
System.out.println("this is before...");
}
@After
public void tearDown() throws Exception {
System.out.println("this is after");
}
@Test
public void test1() {
System.out.println("this is test1...");
}
@Test
public void test2(){
System.out.println("this is test2...");
}
}
而且在内存中它只会存在一份实例,它比较适合加载配置文件。
2.@AfterClass所修饰的方法通常用来对资源的清理,如关闭数据库的连接
3.@Before和@After会在每个测试方法的前后各执行一次。
package com.cyt;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class JunitFlowTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.println("this is beforeClass...");
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println("this is afterClass...");
}
@Before
public void setUp() throws Exception {
System.out.println("this is before...");
}
@After
public void tearDown() throws Exception {
System.out.println("this is after");
}
@Test
public void test1() {
System.out.println("this is test1...");
}
@Test
public void test2(){
System.out.println("this is test2...");
}
}
相关文章推荐
- Linux系统下jailkit的安装与使用示例
- java中static修饰特殊的类
- C++实现模拟定时器
- Jmeter报告优化
- hdu 4288 Coder
- MySQL与oracle日期格式化字符对照表
- Android View measure流程详解
- 相互关注互粉mysql实现
- 谈谈对性能优化的看法,如何做?
- 笔试题59. LeetCode OJ (46)
- eclipse 插件,直接打开文件路径
- ASP.NET MVC之路由特性以及母版页呈现方式(十二)
- SpringMVC接收页面表单参数
- JavaCC -- 生成C++代码
- 详细分析Java中String、StringBuffer、StringBuilder类的性能
- 面试题21
- 移植speex库
- javaの面向对象的总结
- 备份oracle 数据库并且删除几天前的dmp
- uva548--tree(二叉树的递归遍历)