1.junit的设计思想
1.从零开始来应用设计模式,然后一个接一个,直至你获得最终适合的系统架构
1.junit用到的设计模式
1.模板方法模式
1.父类角色:提供模板
2.子类角色:为模板提供实现
一.JUnit在TestCase类中应用了模板方法模式:
public void runBare() throws Throwable {
setUp();
try {
runTest();
}
finally {
tearDown();
}
}
2.适配器模式(Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作)
1. 适配器模式(Adapter Pattern)主要分为三种:
1) 基于类的继承方式
2) 基于对象组合方式
3) 缺省的适配器模式(AWT,Swing事件模型所采用的模式)(父类空实现,子类来实现)
二. JUnit在TestCase类中应用了适配器(Adapter)模式:
在runBare方法中,通过runTest方法将我们自己编写的testXXX方法进行了适配,
public void runBare() throws Throwable {
setUp();
try {
runTest();
}
finally {
tearDown();
}
}
使得JUnit可以执行我们自己编写的Test Case,runTest方法的实现如下:
/**
* Override to run the test and assert its state.
* @exception Throwable if any exception is thrown
*/
protected void runTest() throws Throwable {
assertNotNull(fName);
Method runMethod= null;
try {
// use getMethod to get all public inherited
// methods. getDeclaredMethods returns all
// methods of this class but excludes the
// inherited ones.
runMethod= getClass().getMethod(fName, null);
} catch (NoSuchMethodException e) {
fail("Method \""+fName+"\" not found");
}
if (!Modifier.isPublic(runMethod.getModifiers())) {
fail("Method \""+fName+"\" should be public");
}
try {
runMethod.invoke(this, new Class[0]);
}
catch (InvocationTargetException e) {
e.fillInStackTrace();
throw e.getTargetException();
}
catch (IllegalAccessException e) {
e.fillInStackTrace();
throw e;
}
}
在runTest方法中,首先获得我们自己编写的testXXX方法所对应的Method对象(不带参数),
然后检查该Method对象所对应的方法是否是public的,如果是则调用Method对象的invoke方法来去执行
我们自己编写的testXXX方法。
三。命令模式
1. 将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化,对请求排队,
或记录请求日志,以及支持可撤销的操作
四.组合模式 (TestCase,TestSuit)
1.组合模式又可以叫部分-整体模式
五.如何看源代码
1.调试加不断跟进,断点,debuge进去看源代码,2.看重点内容的源代码
相关推荐
NULL 博文链接:https://lvwenwen.iteye.com/blog/1934965
重点讲到了junit里用到了那些设计模式.
Junit设计模式分析 Junit设计模式分析 Junit设计模式分析 Junit设计模式分析
JUnit设计模式分析 详细讲解JUnit源码中用到的设计模式
Junit设计模式分析,Junit设计模式分析.pdf,Junit设计模式分析.pdf,Junit设计模式分析.pdf
JUnit源码分析.docJUnit源码分析.docJUnit源码分析.docJUnit源码分析.docJUnit源码分析.doc
Junit框架是设计模式应用的经典案例,从中你可以更好的学习和掌握设计模式的使用!
Junit设计模式分析(带源码)
NULL 博文链接:https://liqun.iteye.com/blog/391388
一个参考Junit的设计模式ppt 一个参考Junit的设计模式ppt
Junit设计模式分析
JUNIT 单元测试 设计模式 测试 java 剩下的就只能自己看了
Junit设计模式分析.rar
JUnit设计模式分析及简化的JUnit代码 Junit 中的设计模式 感谢刘兵同志 (技术顾问 bliu76@yeah.net) JUnit 是一个优秀的Java 单元测试框架,由两位世界级软件大师Erich Gamma 和 Kent Beck 共同开发完 成。...
junit 的源码jar包 junit 的源码jar包 junit 的源码jar包