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都统 ...
随机推荐
- elasticsearch 创建索引,以及检索一条数据
elasticsearch的重要概念 我们可以把elasticsearch当做数据库来理解: index:索引库名称,相当于关系型数据库中的表名,一个elasticsearch集群中可以有多个索引库. ...
- Tomcat 7下如何利用 catalina.properties 部署公用类
Tomcat 有很多配置文件,其中一个是 catalina.properties ,本文介绍catalina.properties 中的设置项. 一.组成 catalina.properties ...
- 【GDKOI2016Day1T1-魔卡少女】【拆位】线段树维护区间内所有连续子区间的异或和
题意:给出N个数,M个操作.操作有修改和询问两种,每次修改将一个数改成另一个数,每次询问一个区间的所有连续子区间的异或和.n,m<=100000,ai<=1000 题解: 当年(其实也就是 ...
- Centos 6.5下安装vsftpd服务器
1.查看是否安装vsftp [root@localhost ~]#rpm -qa|grep vsftpd 如果出现 vsftpd-2.2.2-13.el6_6.1.x86_64 则说明已经安装了v ...
- 浅谈游戏中BUFF的设计要点
其实这类帖子并没有多少的设计理论,对于策划的提升和帮助也并不大,原因其实在于其适用性太窄,当我要设计XX象棋的时候,它就滚一边去了. 废话不多说切入正题: 游戏中的BUFF/DEBUFF我们见过很多, ...
- Python第三方库jieba(中文分词)入门与进阶(官方文档)
jieba "结巴"中文分词:做最好的 Python 中文分词组件 github:https://github.com/fxsjy/jieba 特点 支持三种分词模式: 精确模式, ...
- xtrabackup 安装、备份和恢复
xtrabackup 版本对应: 2.4 专针对 5.7 开发的,兼容 5.6, 5.5 2.3 针对 5.6 开发的,兼容5.5 2.2 针对5.5 开发的 安装包下载: wget https:// ...
- selenium 点击浏览器按钮
利用以下的方法,selenium 也可以模拟点击各种浏览器按钮:browser.back()点击“返回”按钮.browser.forward()点击“前进”按钮.browser.refresh()点击 ...
- sicily 1172. Queens, Knights and Pawns
Description You all are familiar with the famous 8-queens problem which asks you to place 8 queens o ...
- sicily 1036. Crypto Columns
Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description The columnar encryption scheme scram ...