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都统 ...
随机推荐
- 51Nod 1094 和为k的连续区间 | 水
Input示例 6 10 1 2 3 4 5 6 Output示例 1 4 #include "cstdio" #include "algorithm" #in ...
- [洛谷P3763] [TJOI2017]DNA
洛谷题目链接:[TJOI2017]DNA 题目描述 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S,有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是研究人员发现对碱基序列S,任意修改其 ...
- 【bzoj2038-小z的袜子】莫队算法
莫队例题. 莫队学习:https://www.cnblogs.com/Paul-Guderian/p/6933799.html 本题 分子是sigma(c(sum[a[i]],2)),分母是sigma ...
- CodeForces 316D3 PE Lesson
time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【BZOJ】1500: [NOI2005]维修数列
[算法]splay [题解]数据结构 感谢Occult的模板>_<:HYSBZ 1500 维修数列 #include<cstdio> #include<cctype> ...
- css3动画总结
- Centos7编译安装Xen环境(vtpm)
编译xen环境(http://www.lvtao.net/server/574.html#comment-1882): yum update yum groupinstall "Develo ...
- 【字符串处理算法】字符串包含的算法设计及C代码实现【转】
转自:http://blog.csdn.net/zhouzhaoxiong1227/article/details/50679587 版权声明:本文为博主原创文章,对文章内容有任何意见或建议,欢迎与作 ...
- python基础===通过菲波那契数列,理解函数
def fib(n): # write Fibonacci series up to n """Print a Fibonacci series up to n.&quo ...
- php文件读取的问题
PHP字符编码问题 首先说下字符编码问题,当我们给定路径后如果路径中包含中文,可能会出现问题,打印到屏幕则显示没问题, 但是读取文件会报错:readfile(E:/素玄文件/app历史版本/素玄ERP ...