Junit4常用注解
Junit4注解
JUnit4的测试类不用再继承TestCase类了。使用注解会方便很多。
@Before:初始化方法
@After:释放资源
@Test:测试方法,在这里可以测试期望异常和超时时间
@Ignore:忽略的测试方法
@BeforeClass:针对所有测试,只执行一次,且必须为static void
@AfterClass:针对所有测试,只执行一次,且必须为static void
一个JUnit 4 的单元测试用例执行顺序为:
@BeforeClass –> @Before –> @Test –> @After –> @AfterClass
每一个测试方法的调用顺序为:
@Before –> @Test –> @After
代码:
public class PersonTest3 {
@BeforeClass
public static void beforeClass(){
System.out.println("beforeClass");
}
@Before
public void before(){
System.out.println("before");
}
@Test
public void testStudy(){
Person p = new Person();
p.study();
}
@Test
public void testPlay(){
Person p = new Person();
p.play();
}
@AfterClass
public static void afterClass(){
System.out.println("afterClass");
}
@After
public void after(){
System.out.println("after");
}
}
class Person {
public void study(){
System.out.println("学习!");
}
public void play(){
System.out.println("玩!");
}
}
输出:
beforeClass
before
学习!
after
before
玩!
after
afterClass
Junit4常用注解的更多相关文章
- Junit4学习(四)Junit4常用注解
一,背景知识: 由前面的知识可以知道: /* * @Test:将一个普通方法修饰为一个测试方法 * @Test(exception=XXX.class) * @Test ...
- Spring系列之Spring常用注解总结
传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...
- Spring常用注解总结
转载自:https://www.cnblogs.com/xiaoxi/p/5935009.html 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点 ...
- Spring注解 系列之Spring常用注解总结
参考:Spring系列之Spring常用注解总结 (1) Resource 默认是byName的方式进行bean配置,@AutoWired默认是按照byType的方式进行装配bean的:(2)Comp ...
- Spring系列之Spring常用注解总结 转载
Spring系列之Spring常用注解总结 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.x ...
- 【转】TestNG常用注解
http://blog.csdn.net/d6619309/article/details/52435084 TestNG的注解大部分用在方法级别上.常用的注解列举如下: 1. Before类别和Af ...
- 23_2spring的常用注解
1.基于注解的IOC配置 1.1导入jar包 <?xml version="1.0" encoding="UTF-8"?> <project ...
- SpringMVC常用注解實例詳解3:@ResponseBody
我的開發環境框架: springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...
- SpringMVC常用注解實例詳解2:@ModelAttribute
我的開發環境框架: springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...
随机推荐
- python and django
[安装(CentOS 6.5)] 安装python, 采用yum install python,安装后为2.6版本 安装django 1.6.4,再高的版本,就需要python提升版本.下载并解压,然 ...
- 怎么获取iOS的私有API
前言 作为iOS开发人员,相信大多数伙伴都对怎么获取iOS的私有API很有兴趣,最近通过查找资料,总结了以下三种方法,希望对你有用. 第一种(class-dump) 不得不说这是一个很棒的工具,安装和 ...
- 转: JSTL SQL标签库 使用
SQL标签库 JSTL提供了与数据库相关操作的标签,可以直接从页面上实现数据库操作的功能,在开发小型网站是可以很方便的实现数据的读取和操作.本章将详细介绍这些标签的功能和使用方法. SQL标签库从功能 ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树
E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casi ...
- launch文件
launch在ROS应用中,每个节点通常有许多参数需要设置,为了方便高效操作多个节点,可以编写launch文件,然后用roslaunch命令运行roslaunch: roslaunch [option ...
- enmo_day_03
安装 装载点 : /u01 (第一个挂载点 LUN1) /u01 (第二个挂载点LUN2) /disk01 目录 : /u01/app/oracle /u01/app/app 文件 : 控制文件 :c ...
- wireshark使用方法(学习笔记一)
wireshark是非常流行的网络封包分析软件,功能十分强大.可以截取各种网络封包,显示网络封包的详细信息.使用wireshark的人必须了解网络协议,否则就看不懂wireshark了. 为了安全考虑 ...
- Wireshark找不到网络接口问题
Wireshark找不到网络接口问题 在运行Wireshark工具抓包时,需要有管理员用户权限.如果是普通用户启动的话,将会提示找不到网络接口.
- LeetCode189——Rotate Array
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- HDU 4822----其实不会这个题
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4822 并不会做这个题,题解说是LCA(最近公共祖先),并不懂,说一下我自己的思路吧,虽然没能实现出来. 题 ...