【Python + Selenium】Mock Testing 是啥?一个so上的高票答案。
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数据库了。你的测试将会包含一些关于写怎样的数据到数据库的判断语句。
我英语怎么这么差,看不懂呀,文化差异吗?
【Python + Selenium】Mock Testing 是啥?一个so上的高票答案。的更多相关文章
- Python+Selenium练习篇之1-摘取网页上全部邮箱
前面已经介绍了Python+Selenium基础篇,通过前面几篇文章的介绍和练习,Selenium+Python的webUI自动化测试算是入门了.接下来,我计划写第二个系列:练习篇,通过一些练习,了解 ...
- Python+Selenium练习篇之18-获取元素上面的文字
本文介绍如何通过Selenium方法来获取某一个元素的text属性值.在很多自动化测试脚本中,需要多次获取元素的text值,拿过来进行对比和匹配.例如,在一个登陆界面,如果不输入用户名和密码,直接点击 ...
- Python+Selenium中级篇之-封装一个自己的类-浏览器引擎类
前一篇文章我们知道了,如何去封装几个简单的Selenium方法到我们自定义的类,这次我们编写一个类,叫浏览器引擎类,通过更改一个字符串的值,利用if语句去判断和控制启动那个浏览器.这里我们暂时,支持三 ...
- Python+Selenium基础篇之5-第一个完整的自动化测试脚本
前面文章,我们介绍了如何采用XPath表达式去定位网页元素,在掌握了如何抓取或者如何书写精确的XPath表达式后,我们可以开始写自己的第一个真正意义上的webui 自动化测试脚本,就相当于,你在学习P ...
- Python + Selenium + AutoIt 模拟键盘实现另存为、上传、下载操作详解
前言 在web页面中,可以使用selenium的定位方式来识别元素,从而来实现页面中的自动化,但对于页面中弹出的文件选择框,selenium就实现不了了,所以就需引用AutoIt工具来实现. Auto ...
- [adb 学习篇] python将adb命令集合到一个工具上
https://testerhome.com/topics/6938 qzhi的更全面,不过意思是一样的,另外补充一个开源的https://github.com/264768502/adb_wrapp ...
- Python+Selenium练习篇之11-浏览器上前进和后退操作
本文来介绍上如何,利用webdriver中的方法来演示浏览器中地址栏旁边的前进和后退功能. 相关脚本代码如下: # coding=utf-8import timefrom selenium impor ...
- 学霸笔记系列 - Python Selenium项目实战(一)—— 怎么去验证一个按钮是启用的(可点击)?
Q: 使用 Python Selenium WebDriver 怎么去验证一个按钮是启用的(可点击)? A:Selenium WebDriver API 里面给出了解决方法is_enabled() 使 ...
- python selenium 常见问题列表
python selenium webdriver 常见问题FAQ 另一个FAQ: https://code.google.com/p/selenium/wiki/FrequentlyAskedQue ...
随机推荐
- html上下结构(上部固定高度,下部平铺)
html页面上下结构: 上部固定,下部平铺 <div id="page_header"></div> <div id="page_conte ...
- package.json 字段全解析
Name 必须字段. 小提示: 不要在name中包含js, node字样: 这个名字最终会是URL的一部分,命令行的参数,目录名,所以不能以点号或下划线开头: 这个名字可能在require()方法中被 ...
- 点 击 直 接加我QQ的功能
<a target="_blank" href="tencent://message/?uin=2814920598&Site=&Menu=yes& ...
- eclipse安装genymotion插件。
先发个我自己压缩的genymotion和VirtualBox,下载链接:http://pan.baidu.com/s/1o7wgJiU 1.在安装genymotion之后,打开eclipse,如下图操 ...
- APP性能测试之卡顿比(FPS)
fps概念: FPS是图像领域中的定义,是指画面每秒传输帧数,通俗来讲就是指动画或视频的画面数.FPS是测量用于保存.显示动态视频的信息数量.每秒钟帧数愈多,所显示的动作就会愈流畅. 卡顿人体感觉标准 ...
- crawler4j 学习
crawler4j 学习(一) crawler4j是一个轻量级多线程网络爬虫,开发者可以调用相应的接口在短时间内创建一个多线程网络爬虫. 前期准备 使用maven 为了使用最近版本的crawler4j ...
- MySQL黑科技用法总结(持续更新)
1.利用set插入数值 insert [into] 表名 set 列=值. 2.利用select对字段进行测试 ) ,并且有2条记录 ',num1+1的计算结果 tips:相等返回1,否则返回0 f ...
- python字符串前面加r
在Python的string前面加上'r', 是为了告诉编译器这个string是个raw string,不要转意backslash '\' . 例如,\n 在raw string中,是两个字符,\和n ...
- Lua模块
在lua中,我们可以直接使用require(“model_name”)来载入别的文件,文件的后缀名是.lua,载入的时候直接执行那个文件了. 比如:my.lua 文件中 print(“hello wo ...
- 手把手教你编写Logstash插件
使用过Logstash的朋友都知道,它强大的插件生态几乎覆盖了所有的开源框架.从基本的http.tcp.udp.file,到强大的kafa.redis.ganglia,还有丰富的解析工具,比如date ...