There are many kinds of testing which really made me confused.

To be honest, I've never heard of something like Mock testing, stub testing. I had to learn a lot before I can know little about testing.

Whenever I saw something which was written by some foreign guys in several years ago, I felt so bad as I fell behind for lots of knowlege and it's even impossible for me to catch up with. Anyhow, just start!

I'm going to build a framework for our daily testing website. It's a longlong journey.

维基对python 测试工具的分类。得一个个研究呀!

https://wiki.python.org/moin/PythonTestingToolsTaxonomy

  • Mock Testing: 

转一个stackoverflow上的高票答案

Prologue: If you look up the noun mock in the dictionary you will find that one of the definitions of the word is something made as an imitation.

你在字典上查这个词呀,Mock啥意思,就是一个模仿/模拟出来的东西。


Mocking is primarily used in unit testing. An object under test may have dependencies on other (complex) objects. To isolate the behaviour of the object you want to test you replace the other objects by mocks that simulate the behavior of the real objects. This is useful if the real objects are impractical to incorporate into the unit test.

In short, mocking is creating objects that simulate the behaviour of real objects.

Mocking在单元测试里用的多,(单元测试 多用白盒,集成测试多用灰盒,系统测试黑盒,嗯复习一下)。你测试的对象很可能会依赖一些其他复杂的对象。把其他的对象都用Mocks替代,这样可以隔离出你想测的对象的行为。当真实对象很难被在包含在单元测试中的时候,mock很有用。

简单说,mocking就是你创建一些对象来模拟真实对象的行为。


At times you may want to distinguish between mocking as opposed to stubbing. There may be some disagreement about this subject but my definition of a stub is a "minimal" simulated object. The stub implements just enough behaviour to allow the object under test to execute the test.

A mock is like a stub but the test will also verify that the object under test calls the mock as expected. Part of the test is verifying that the mock was used correctly.

To give an example: You can stub a database by implementing a simple in-memory structure for storing records. The object under test can then read and write records to the database stub to allow it to execute the test. This could test some behaviour of the object not related to the database and the database stub would be included just to let the test run.

If you instead want to verify that the object under test writes some specific data to the database you will have to mock the database. Your test would then incorporate assertions about what was written to the database mock.

你可能又想区分mocking和stubbing,说出来有些人可能不同意,他理解就是一个stub,是小的模拟对象。你这个测试能执行起来,肯定需要一些很基本,最起码的一些对象。stub就是提供能让测试跑起来的最基本的模拟对象。

mock虽然跟stub像,但是除此之外,温饱之外的小康,mock一会验证你的这臆造出来的对象是意料之中的,验证这对象是不是你想模拟的对象。mock 测试中会验证这mock 用对了地方。

举个栗子,你可以stub(空桩)造一个只有最基本结构的简易数据库去存储你的数据。你要测试的对象可以去这个简易数据库里读写数据,你的测试可以跑起来的。但是你这过程中可能会测试一些跟数据库无关的东西,并不是你真正想测的。而且,这个简易数据库只是为了让你test能跑起来而造的。

你的测试可以跑起来了,你又想测些特定数据,那么你必须mock数据库了。你的测试将会包含一些关于写怎样的数据到数据库的判断语句。

我英语怎么这么差,看不懂呀,文化差异吗?

最新文章

  1. cocos2d之json使用实例
  2. eclipse无法自动识别出svn项目
  3. 无废话ExtJs 入门教程十[单选组:RadioGroup、复选组:CheckBoxGroup]
  4. sqlmap基本命令
  5. perl中的grep函数介绍
  6. ArcGIS栅格数据的合并和剪切
  7. public、private、protected 与 默认 等访问修饰符
  8. JavaScript执行上下文
  9. ios专题 -归档保存数据
  10. 大数据分析神兽麒麟(Apache Kylin)
  11. 关于java中Double类型的运算精度问题(转)
  12. 数组对象元素的添加,String对象,BOM对象以及文档对象的获取
  13. Poj2761-Feed the dogs(伸展树求名次)
  14. jqeury显示前几个,隐藏后几个,点击后隐藏前几个显示后几个
  15. postMessage 实现跨源通信 iframe 跨域获取url
  16. php脚本#!/usr/bin/env php 写法
  17. Ftp命令使用
  18. NuGet的几个小技巧(转)
  19. zoj3814
  20. spring mvc与mybatis整合错误提示

热门文章

  1. 2016 Multi-University Training Contest 1
  2. CodeForces 514B
  3. 解决webstorm卡顿问题
  4. log4php的配置
  5. $Ajax简单理解
  6. STM32之位绑定
  7. JavaScript之闭包就是个子公司
  8. 使用太过简单jqprint源码也极其简洁易懂
  9. HDU 1166 敌兵布阵(分块)
  10. win 10 常见问题