JUnit basic annotation
来源:互联网 发布:单身狗 知乎 编辑:程序博客网 时间:2024/05/20 03:45
一个标准的Junit 4的运行流程,大致如下:
测试类实例化 -> @BeforeClass -> @Before -> @Test -> @After -> @AfterClass
下面的代码输出明确表明了其运行流程:
测试类实例化 -> @BeforeClass -> @Before -> @Test -> @After -> @AfterClass
下面的代码输出明确表明了其运行流程:
package com.junit.tutorial;import org.junit.*;import static org.junit.Assert.*;import java.util.*; /** * @author mkyong * */public class BasicAnnotation { 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 - testOneItemCollection
@After - tearDown
@Before - setUp
@Test - testEmptyCollection
@After - tearDown
@AfterClass - oneTimeTearDown
需要注意的是,我们需要申明 @BeforeClass 和 @AfterClass 为静态方法。
0 0
- JUnit basic annotation
- JUnit Annotation
- JUnit Annotation
- junit annotation
- junit annotation
- junit @annotation
- 03Junit Junit的annotation
- 14 Annotation Junit 异常
- JUnit的annotation
- JUnit中的注解(Annotation)
- JUnit中标注Annotation介绍
- JUnit Annotation——JUnit单元测试中批注@详解
- Junit的annotation(注释、注解)
- JUnit 4 常用的几个annotation 介绍
- JUnit中使用Annotation获得实例
- JUnit 4中annotation的用法
- UIAutomator2.0详解(JUnit Annotation篇)
- JUnit 4 使用 Java 5 中的注解(annotation)
- 浅论Android网络请求库——android-async-http
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
- root后还是打不开data/data
- adb 打印指定进程的log信息
- eclipse解压后无法启动
- JUnit basic annotation
- C语言(五)extern和static关键字
- 基于W5500的NetBIOS应用实例
- cocos2dx的retain与release
- 微软发力抢占移动平台市场(Office、Acompli、Outlook、Sunrise等)
- android fragment与ViewPager
- js调用flex的代码
- bwlabel和bwconncomp区别
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)