Junit3.8源码--核心类
好久没画图了,看下这个序列图,还算比较清晰的:
以textui来分析:
Test
顶层接口。TestSuite和TestCase均实现此接口,在具体执行的时候面向此接口编程,弱化类型,实现各自的执行流程。
TestSuite中的run方法:
public void run(TestResult result) {
for (Enumeration e= tests(); e.hasMoreElements(); ) {
if (result.shouldStop() )
break;
Test test= (Test)e.nextElement();
runTest(test, result);
}
}
public void runTest(Test test, TestResult result) {
test.run(result);
}
如果当前Test是TestSuite类型的,上面的runTest将会继续调用其上的run方法,遍历其维护的Test集合,如果遍历的是TestCase,将走常规路线,否则依旧。
这样就相当于由树到叶的过程,最终的run在叶节点。
TestRunner
测试运行类。
启动测试用例
通过调用BaseTestRunner的getTest方法来获取TestSuite。
TestSuite
测试集合类
构建用户自定义的测试集合。将一组方法整合在一起来测试,自定义组合。如果用户不定义suite方法来创建Testsuite,框架默认生成一个,包含所有的测试方法(TestCase)。
Method suiteMethod= null;
try {
suiteMethod= testClass.getMethod(SUITE_METHODNAME, new Class[0]);
} catch(Exception e) {
// try to extract a test suite automatically
clearStatus();
return new TestSuite(testClass);
}
如果我们自己来构建就是这样:
public static Test suite(){
TestSuite suite = new TestSuite();
// 自定义类集合
suite.addTestSuite(DemoTest.class);
suite.addTestSuite(DemoTwoTest.class);
return suite;
}
跟踪一下addTestSuite方法:
public void addTestSuite(Class testClass) {
addTest(new TestSuite(testClass));
}
public void addTest(Test test) {
fTests.addElement(test);
}
这个过程可以让顶层的TestSuite包含两个子TestSuite,一个是关于DemoTest的,另一个是DemoTwoTest,两者又包含了各自的TestCase。
TestCase
测试用例类
为每个测试方法创建一个TestCase。包含一个最本质的run方法,仅仅持有该方法的名称,利用反射来调用测试方法。
/**
* Runs the test case and collects the results in TestResult.
*/
public void run(TestResult result) {
result.run(this);
}
TestCase的run方法会调用TestResult的run
TestResult
测试结果类
维护测试结果。最基本的测试方法最终都会在这里运行,方便统计结果。
/**
* Runs a TestCase.
*/
protected void run(final TestCase test) {
startTest(test);
Protectable p= new Protectable() {
public void protect() throws Throwable {
test.runBare();
}
};
runProtected(test, p);
endTest(test);
}
/**
* Runs a TestCase.
*/
public void runProtected(final Test test, Protectable p) {
try {
p.protect();
}
catch (AssertionFailedError e) {
addFailure(test, e);
}
catch (ThreadDeath e) { // don't catch ThreadDeath by accident
throw e;
}
catch (Throwable e) {
addError(test, e);
}
}
TestResult的run又反过来调用TestCase的runBare
Junit3.8源码--核心类的更多相关文章
- MyBatis源码 核心配置解析 properties元素
XMLConfigBuilder的parseConfiguration(XNode)方法,用于解析配置文件 XMLConfigBuilder的propertiesElement(XNode)方法,用于 ...
- mybatis源码核心代码
/** * mybatis源码测试类 * @param args * @throws IOException * @see org.apache.ibatis.session.Configuratio ...
- zepto源码--核心方法(类数组相关)--学习笔记
从这篇起,在没有介绍到各类插件之前,后面将陆续介绍zepto对外暴露的核心方法.即$.fn={}里面的所有方法的介绍.会配合zepto的API进行介绍. 其实前面已经介绍了几个,如width,heig ...
- 深入源码解析类Route
微软官网对这个类的说明是:提供用于定义路由及获取路由相关信息的属性和方法.这个说明已经很简要的说明了这个类的作用,下面我们就从源码的角度来看看这个类的内部是如何工作的. public class Ro ...
- ABP源码uml类图
陆陆续续学习ABP框架有一段时间了,阳光铭睿的入门教程和HK Zhang的源码分析文章对我的学习帮助都很大.之所以会花这么大工夫去学习ABP.看ABP的源代码,一是因为本人对于DDD也非常有兴趣,AB ...
- Caffe源码-Solver类
Solver类简介 Net类中实现了网络的前向/反向计算和参数更新,而Solver类中则是对此进行进一步封装,包含可用于逐次训练网络的Step()函数,和用于求解网络的优化解的Solve()函数,同时 ...
- Caffe源码-SGDSolver类
SGDSolver类简介 Solver类用于网络参数的更新,而SGDSolver类实现了优化方法中的随机梯度下降法(stochastic gradient descent),此外还具备缩放.正则化梯度 ...
- Caffe源码-Net类(下)
net.cpp部分源码 // 接着上一篇博客的介绍,此部分为Net类中前向反向计算函数,以及一些与HDF5文件或proto文件相互转换的函数. template <typename Dtype& ...
- Caffe源码-Net类(上)
Net类简介 Net类主要处理各个Layer之间的输入输出数据和参数数据共享等的关系.由于Net类的代码较多,本次主要介绍网络初始化部分的代码.Net类在初始化的时候将各个Layer的输出blob都统 ...
随机推荐
- [洛谷P2704] [NOI2001]炮兵阵地
洛谷题目链接:[NOI2001]炮兵阵地 题目描述 司令部的将军们打算在NM的网格地图上部署他们的炮兵部队.一个NM的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示), ...
- mysql创建用户,并授权
1.创建用户 CREATE USER 'username'@'host' IDENTIFIED BY 'password'; host分下列3种情况:'%' - 所有情况都能访问‘localhost’ ...
- Proxmap Sort
这个排序是桶排序和基数排序的改进,理解了前两者,这个排序很容易理解 先回忆下桶排序是怎么回事,它与桶的区别在于入桶规则,桶排序里是1入1号桶,2入2号桶 这个排序把数字分区了,然后给出一个所谓的键,例 ...
- rabbitmq使用命令创建交换机、队列及绑定
http://www.jusene.me/2018/02/20/rabbitmq-2/
- 自定义View的实现流程
1.继承View组件,比如,LabelView继承了View 2.重写两个构造方法,比如,对于自定义View LabelView LabelView(Context context),如果该自 ...
- MySQL增删改查之查询
(7)范围查询select * from car where price>40 and price<60 --查询价格在40-60之间的select * from car where ...
- UIPikerView的属性---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/C ...
- UIPageControl---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...
- HDU 1728 逃离迷宫 (广搜)
题目链接 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...
- mssql注入中的储存用法删除与恢复
删除: use master exec sp_dropextendedproc 'xp_cmdshell' exec sp_dropextendedproc 'xp_enumgroups' exec ...