test md
Glossary
- SUT SYSTEM UNDER TEST
- CUT CLASS UNDER TEST
- MUT METHOD UNDER TEST
Tests without Use of Stub
You do not have to use stub when there are no external dependencies involved in the system under test (SUT). The point is only take it into consideration when you really need it
'''CUT'''
class LogAnalyzer_NoUseStub(object):
def IsValidLogFileName(self, fileName):
return str(fileName).endswith('.sln')
''' TEST CASE'''
class LogAnalyzerTestCase(unittest.TestCase):
# No stub used just simply perform the test
def test_IsValidLogFileName_BadExtension_ReturnFalse_NoStub(self):
logAnalyzer0 = LogAnalyzer_0()
ret = logAnalyzer0.IsValidLogFileName('fn1.sl')
self.assertFalse(ret)
Tests Must Use Stub
However somethimes we have to rely on the extenal class or method that we cannot control on it or it has not been finished yet. This is when we need stub to help us. eg, draw_from_weighted_range() and randrange(), interacting with filesystem. Fakes here include stub (assert on CUT) and mock (assert on Fake) we talk about stub and mock in later posts. Say our IsValidLogFileName() method needs read through the config file and return true if extension is supported in config file.
There two big types to inject fakes into MUT(Method Under Test):
- Test are performed on the MUT itself (eg. assert(mut.dosomething(),true)
- Step 1 - Abstracting concrete objects into interfaces or delegates
How: Extract an interface to allow replacing or extending underlying impl - Step 2 - Refactoring to allow injection of faked implementations of those delegates or interface
How:
- Inject stub in code under test using factory design (layer of indirection 2 faking a member in factory class)
the difference is that the object initiating the stub request is the code under test. the fake instances was set by code external to the code under test before the test started in the below. A test configures the factory class to re turn a stub object. The class usess the factory class to get the stub instance, which in production code would return an object that is not a stub Preferred to using this layer
- Injection of a stub in test code (layer of indiretion 1 faking a member in class under test)
- Inject stub via ctor (cumbersome whenyou have many dependencies)
- Inject stub via setter/getter
This is much simpler than ctor injection as each test can set only the dependencies that it needs to get the test underway;
Use this when you want to signify that the dependency is optional or the dependency has a default instance created that does not create any problems; - Inject stub impl via parameter
- Test are performed on the class that inhetites from MUT (eg. assert(mut_child.dosomething(),true)
It is also known as Extract and override, which is is good to for sumulating inputs into your code under test(in other words, return values from dependency). but it is cumbersome when you want t verify and check interactions that are coming out of the code under test int othe dependency (in other words, it is good to play stub but very bad to play mock)
- use local virtual factory method to get instance of stub
The time not to use this is there is an interface ready to fake or there is already a place that seam can be injected. - use extract and override to return a logical result instead of calling an actual denpendency
This uses a simple faked result instead of a stub
Much easier than 2.1 preferred to use
test md的更多相关文章
- 好用的Markdown编辑器一览 readme.md 编辑查看
https://github.com/pandao/editor.md https://pandao.github.io/editor.md/examples/index.html Editor.md ...
- github上readme.md 格式
参考:https://github.com/guoyunsky/Markdown-Chinese-Demo/edit/master/README.md
- .md文件的语法
md全称是Macdown,.md文件可以当记事本一样使用,作为编辑软件,还可以自己添加样式,图片,链接等,可以用记事本打开,也可以保持样式排版转换为html文件,语法比较简单..md除了编辑容易的优势 ...
- md语法之行内代码和代码片续集
md语法之行内代码和代码片 一行之内嵌入一小段代码, 简称行内代码. 其方法为: 用撇号把代码围起来. 比如: import numpy as ny就可以了. 代码片的方法: 三个连续的撇号+pyth ...
- md语法之行内代码和代码片
md语法之行内代码和代码片 比如说要在行内写上一句或者半句代码(代码的意思就是某种脚本语言), 用撇号围起来就可以了. 比如: import pandas as pd 写代码片(单独的一块脚本语言)的 ...
- bootstrap 之 xs,sm,md,lg && 主要颜色
mobile – xs ( <768px ) tablet – sm ( 768~991px ) desktop – md ( 992~1170px ) large desktop – lg ( ...
- Markdown(MD)写作
简洁的写作 目前正逐步使用Makedown来写博客或其它的文档,本文记录一下Markdown的相关知识 Markdown语法 标题 # 内容 (一级标题) ## 内容 (二级标题) ### 内容 (三 ...
- /MT、/MD编译选项,以及可能引起在不同堆中申请、释放内存的问题
一.MD(d).MT(d)编译选项的区别 1.编译选项的位置 以VS2005为例,这样子打开: 1) 打开项目的Property Pages对话框 2) 点击左侧C/C ...
- 警告 - no rule to process file 'WRP_CollectionView/README.md' of type net.daringfireball.markdown for architecture i386
warning: no rule to process file '/Users/mac/Downloads/Demo/Self/WRP_CollectionView/WRP_CollectionVi ...
- Markdown语言.md文件
转自:http://www.kuqin.com/shuoit/20141125/343459.html 之前一直在使用github,也在上面分享了不少的项目和Demo,每次创建新项目的时候,使用的都是 ...
随机推荐
- bootstrap注意事项(七)图片
在本章中,我们将学习 Bootstrap 对图片的支持.Bootstrap 提供了三个可对图片应用简单样式的 class: .img-rounded:添加 border-radius:6px 来获得图 ...
- 蓝桥杯D1
整数因式分解的问题.了解了一下筛法计算素数的算法.之前都是直接跑的sqrt(n)... 上方的genPrime()即筛法.大致意思是开一个标识数组,通过循环,下标为合数的位置置为false. #inc ...
- 02151216--Ajax
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Windows下载安装jmeter
一.下载 jmeter下载地址: http://jmeter.apache.org/download_jmeter.cgi Binaries-apache-jmeter-3.0.zip 二.安装 1. ...
- python之字符串格式化(format)
用法: 它通过{}和:来代替传统%方式 1.使用位置参数 要点:从以下例子可以看出位置参数不受顺序约束,且可以为{},只要format里有相对应的参数值即可,参数索引从0开,传入位置参数列表可用*列表 ...
- 不可综合的verilog语句分析
前半部分转自http://www.cnblogs.com/Mrseven/articles/2247657.html,后半部分为自己测试结果. 基础知识:verilog 不可综合语句 (1)所有综合工 ...
- cocos2d-x -------之笔记篇 动画的实现
cocos2d-x 动画的实现 一.实现原理 动画的实现其实就是使用一个完整的动作图片集来实现动画,达到动态的效果 动画动作类(CCAnimate)是加载一个动画类来实现动作. 动画类(CCAnima ...
- LINUX常用命令-系统配置篇(二)
学到一定程度了就会关注系统方面的一些配置,只是就需要相关的命令了.现在把Linux查看系统配置常用命令列出来 # uname -a # 查看内核/操作系统/CPU信息# head -n 1 /etc/ ...
- Linux主要发行版本介绍
Linux主要发行版本介绍 1.Red Hat Linux Red Hat是一个比较成熟的Linux版本,无论在销售还是装机量上都比较可观.该版本从4.0开始同时支持Intel.Alpha及Sparc ...
- php面向对象编程学习之高级特性
前几天写了一篇关于php面向对象基础知识的博客,这两天看了php面向对象的高级特性,写出来记录一下吧,方便以后拿出来复习. 面向对象除了最基本的定义类之外,最主要就是因为面向的一些高级特性,运用这些高 ...