本教程介绍了在JUnit4中支持的基本注解。

import org.junit.*;
import static org.junit.Assert.*;
import java.util.*; /**
* @author yiibai
*
*/
public class JunitTest1 { private Collection collection; @BeforeClass
public static void oneTimeSetUp() {
// one-time initialization code
System.out.println("@BeforeClass - oneTimeSetUp");
} @AfterClass
public static void oneTimeTearDown() {
// one-time cleanup code
System.out.println("@AfterClass - oneTimeTearDown");
} @Before
public void setUp() {
collection = new ArrayList();
System.out.println("@Before - setUp");
} @After
public void tearDown() {
collection.clear();
System.out.println("@After - tearDown");
} @Test
public void testEmptyCollection() {
assertTrue(collection.isEmpty());
System.out.println("@Test - testEmptyCollection");
} @Test
public void testOneItemCollection() {
collection.add("itemA");
assertEquals(1, collection.size());
System.out.println("@Test - testOneItemCollection");
}
}

运行结果:

@BeforeClass - oneTimeSetUp
@Before - setUp
@Test - testEmptyCollection
@After - tearDown
@Before - setUp
@Test - testOneItemCollection
@After - tearDown
@AfterClass - oneTimeTearDown

在JUnit 4中,必须声明“@BeforeClass”和“@AfterClass”的方法是静态方法。

JUnit4 基本用法实例的更多相关文章

  1. php中的curl使用入门教程和常见用法实例

    摘要: [目录] php中的curl使用入门教程和常见用法实例 一.curl的优势 二.curl的简单使用步骤 三.错误处理 四.获取curl请求的具体信息 五.使用curl发送post请求 六.文件 ...

  2. 上传文件及$_FILES的用法实例

    Session变量($_SESSION):�php的SESSION函数产生的数据,都以超全局变量的方式,存放在$_SESSION变量中.1.Session简介SESSION也称为会话期,其是存储在服务 ...

  3. C++语言中cin cin.getline cin.get getline gets getchar 的用法实例

    #include <iostream> #include <string> using namespace std; //关于cin cin.getline cin.get g ...

  4. Union all的用法实例sql

    ---Union all的用法实例sqlSELECT TOP (100) PERCENT ID, bid_user_id, UserName, amount, createtime, borrowTy ...

  5. 【转】javascript入门系列演示·三种弹出对话框的用法实例

    对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...

  6. php strpos 用法实例教程

    定义和用法该strpos ( )函数返回的立场,首次出现了一系列内部其他字串. 如果字符串是没有发现,此功能返回FALSE . 语法 strpos(string,find,start) Paramet ...

  7. 【JSP】三种弹出对话框的用法实例

    对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...

  8. python多线程threading.Lock锁用法实例

    本文实例讲述了python多线程threading.Lock锁的用法实例,分享给大家供大家参考.具体分析如下: python的锁可以独立提取出来 mutex = threading.Lock() #锁 ...

  9. jQuery中on()方法用法实例详解

    这篇文章主要介绍了jQuery中on()方法用法,实例分析了on()方法的功能及各种常见的使用技巧,并对比分析了与bind(),live(),delegate()等方法的区别,需要的朋友可以参考下 本 ...

随机推荐

  1. android alipay

    "java.security.spec.InvalidKeySpecException" KeyFactory keyFactory =KeyFactory.getInstance ...

  2. 多媒体文件格式之TS

    [时间:2016-07] [状态:Open] TS流是MPEG-2标准中定义一种用于直播的码流结构,具有很好的容错能力.所有跟TS相关的标准可以从ISO/IEC_13818-1中找到. 通常TS流的后 ...

  3. Python(四)之Python流程控制(if、while、for)

    Python流程控制 if测试: if 条件测试表达式: 组合条件测试: x and y:与运算 x or y:或运算 not x:非运算 while: break:跳出最内层的循环 continue ...

  4. How To Install Java with Apt-Get on Ubuntu 16.04

    Introduction Java and the JVM (Java's virtual machine) are widely used and required for many kinds o ...

  5. Python爬虫技巧

    Python爬虫技巧一之设置ADSL拨号服务器代理 reference: https://zhuanlan.zhihu.com/p/25286144 爬取数据时,是不是只能每个网站每个网站的分析,有没 ...

  6. mysql性能优化(一)

    随着项目的上线,关注开始关注服务器的运维和优化,其中后端数据库状态查看和参数调优是比不可少的一步,可能用到的两个小工具: mysqltuner.pl tuning-primer.sh 参考: [1] ...

  7. [emacs] org-mode的一些小技巧

    Table of Contents 1 快速输入 #+BEGIN_SRC … #+END_SRC 2 代码按语法高亮 3 导出成HTML时的一些问题和技巧 3.1 生成目录表 3.2 为每个分节的标题 ...

  8. Linux下nginx 的常用命令

    启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /us ...

  9. 【转】Lombok:让JAVA代码更优雅

    原文地址:http://blog.didispace.com/java-lombok-1/ 关于Lombok,其实在网上可以找到很多如何使用的文章,但是很少能找到比较齐全的整理.我也一直寻思着想写一篇 ...

  10. iOS five years[转]

    原文链接:http://blog.ayaka.me/post/127980091987/5-years This morning, I got a push notification from Tim ...