JUnit套件测试实例

“套件测试”是指捆绑了几个单元测试用例并运行起来。在JUnit中,@RunWith 和 @Suite 这两个注解是用来运行套件测试。

下面的例子演示这两个单元测试:JunitTest1 和 JunitTest2,在执行JunitTest5 后会一起运行。

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/**
 * JUnit Suite Test
 * @author yiibai
 *
 */

@RunWith(Suite.class)
@Suite.SuiteClasses({
        JunitTest1.class,
        JunitTest2.class
})
public class JunitTest5 {
}

输出结果如下:

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

P.S 结果是从JunitTest1和JunitTest2单元测试的结果汇总起来。

 

posted @   cnetsa  阅读(57)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示