初探Junit的JunitCore类

本文作为Junit系列的开篇,探讨JunitCore这一核心类。尽管该类在Junit4.0以上版本已不常用,但了解其工作原理对理解Junit框架至关重要。案例中展示了如何使用JunitCore,并预告了后续将介绍@Test注解。
摘要由CSDN通过智能技术生成

上两篇学习Junit的文章,主要说了一些Junit的基本运行类,这篇文章博主认为才是走进Junit的开山篇。博主年龄比较大,也比较愚钝,学习这款大湿们认为最简单的开源框架,博主学习很费力,但是学习Junit的时候不得不承认收获不少,所以,只有用黑白文字用说不太清楚的方式记录下来整个学习路程,虽然今天想放弃继续更新blog,但是,还是坚持为好,步入正题。

还是老习惯以一个Junit自带案例入手,作为开山篇,我们简略了解一下JunitCore这个Junit的核心类,案例如下:

package org.junit.tests.deprecated;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.RunWith;

/**
 * @deprecated This is a simple smoke test to make sure the old JUnit4ClassRunner basically works.
 *             Delete this test when JUnit4ClassRunner goes to the Great Heap In The Sky.
 */
@Deprecated
public class JUnit4ClassRunnerTest {

    @SuppressWarnings("deprecation")
    @RunWith(JUnit4ClassRunner.class)
    public static class Example {
        @Test
        public void success() {
        }

        @Test
        public void failure() {
            fail();
        }
    }

    @Test
    public void runWithOldJUnit4ClassRunner() {
        Result result = JUnitCore.runClasses(Example.class);
        assertThat(result.getRunCount(), is(2));
        assertThat(result.getFailureCount(), is(1));
    }

    @SuppressWarnings("deprecation")
    @RunWith(JUnit4ClassRunner.class)
    public static class UnconstructableExample {
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值