JUnit4 基本用法实例
来源:互联网 发布:linux下多线程机制 编辑:程序博客网 时间:2024/05/29 09:50
本教程介绍了在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”的方法是静态方法。
1 0
- JUnit4 基本用法实例
- Junit4单元测试的基本用法 环境搭建
- junit4实例
- Lucene 实例 -- 基本用法
- hive基本用法实例
- JSP基本用法实例
- JFreeChart基本的用法实例
- JUnit4注解基本介绍
- JUnit4注解基本介绍
- junit4的基本注解
- JUnit4 注解基本介绍
- Junit4实例图解[收藏]
- JUnit4概述及实例
- Junit4简单实例介绍
- JUnit4用法总结
- JUnit4用法详解
- JUnit4用法详解
- JUnit4的用法介绍
- 设计模式学习笔记(四):简单工厂模式
- 我所理解的Cocos2d-x OpenGL ES 2.0 概览
- Spark算子:RDD键值转换操作(4)–cogroup/join
- JavaScript判断浏览器版本(未测试)
- <Python进阶读书笔记>之(五) 条件表达式
- JUnit4 基本用法实例
- git push常用命令
- 11. Container With Most Water
- sql---distinct函数用法
- 如何使用rem单位
- bzoj2115
- jQuery实现的进度条效果(未测试)
- Rightmost Digit
- Android富文本编辑器RichEditor的使用