python--unittest测试框架
unittest中最核心的四个概念是:test case, test suite, test runner, test fixture
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAg8AAAH5CAYAAAAGBt07AAAABHNCSVQICAgIfAhkiAAAAAFzUkdCAK7OHOkAAAAEZ0FNQQAAsY8L/GEFAAAACXBIWXMAAAsSAAALEgHS3X78AAArkUlEQVR4Xu3dDbAkVX0ocDUpBDU+U0oqfkSNMX4QgXt1HwFBliWAfGTly0UgQRJ41COijwdI+FKK2jwDArVr0PD4kEiMokLUZ0qU0lCWVYB8vYfrg5gnHwXK14aFBVZwQXbP69P39DIzzL27s7dvT5++v1/VqTt9Tk+fmT7/Of2fnp47LwIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAeectb3vK/Jicn18a/qQoAaMK73/3usLGSVm3UsMcRS2p+0e///u9/IyYP8W+qAgCaMOwAPVjSqrV54xvf+D+32Wabu9PiUMMeRyypebNtSt8wLPYGS1q1KS9+9atf/V/f+c53/mT77bd/atttt31k1LNuztYBc6KpiXFT+qjWefnLX75bqqrFpvQNVZzMVNKqs7YpCe3v/M7vnDDbxzDsbJ1kGpi1jU1KxYF8j3e84x23FBPQM+9617t+XkxoJ6amF73pTW/6YnXfV7ziFQtT9X+K75BiXdH+j7GiWqe3lGsOqNqmSx567zvbvntvV2aq+63f+q33Fu8A/614B/ir1DTjviFv1bgPxkNdNmXbf/RHf/SzuM5rXvOa/1IsbrXFFlts8+Y3v/mKqdbNN5fPC5gnqolk2GRSHJR3mZiY+HXvOrH89m//9oeqVaoJLh5Ei+UXv/71r/90XC7q/19sjyv13rcqsX5Q1bYpyUNhVn333q7MVFckB/f2tm/CviFjvWOaqvpMlzgW7/C/Ge8T46VYfGmq+2qsq9799267KrF+UJGoPp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bfm2Pb2YmnqGl2jy5xmsUzjzzzPICyOinP/3phmsONrct+sY3vhEOPPDAsGLFivCrX/2qbD/kkEPCN7/5zbTGlLhfPvnJT5ZnLuJHFkceeWS44oorUms7mWz7tTm+2TjxDC3V5sl1+fLl4XOf+1xamhIP8PFahs1ti2Jy8U//9E9lAvHHf/zHYfHixeHLX/5y2dYr7pevf/3rYdGiRWHhwoVlMtJ7BqONTLb92hzfbJx4hpYyuU4vx/1isu0nvvMmnqGlTK7Ty3G/mGz7ie+8iWdoKZPr9HLcLybbfuI7b+IZWsrk2i0m237iO2/iGVrK5NotJtt+4jtv4hlayuTaLSbbfuI7b+IZWsrk2i0m237iO2/iuUbFjry52qFKO8rk5ORNaXiyUz0HuqEazzS88574zpt4rlG1M5V2lTQ82akeP92QezzWTXznTTzXyIuhXXIPbvHULbnHY93Ed97Ec428GNol9+AWT92SezzWTXznTTzXyIuhXXIPbvHULbnHY93Ed97Ec428GNol9+AWT92SezzWTXznTTzXyIuhXXIPbvHULbnHY93Ed97Ec428GNol9+DuUjz95V/+ZTjqqKNmfTtnucdj3boU3+Nw9913h4svvjh88IMfTDXNEs818mJol9yDu0vxNJuEofd2znKPx7qNK74PPfTQdGt26trO5tpvv/3CmWeeObY5QjzXaFwvBobLPbjFU7fkHo91G1d819XnOB77MON6HNX4peFkNqqdSTvkHtziqVtyj8e6jSO+qz57+37mmWfC0qVLw8KFC8PRRx8dVq5cWdZHt912WzjssMPCrrvuGi699NJUO3w70Ve/+tWwePHisMsuu5QfKfS66qqrwj777BP23nvvcN1116Xa6fuY6XH16u2/SdVzT8PJbAwGEuOVe3CLp27JPR7rNq74HuzzoosuCqecckp48skny4P3GWeckVpCebC/9dZbw+OPPx6WL1+eaqcMbuc73/lOWLJkSbj99tvDE088ES644ILUMuWcc84JjzzySLj22mvDwQcfnGqn72Omx9VrHPswqsYvDSezUe1M2iH34BZP3ZJ7PNZtXPE92Of+++8fHnjggfL2mjVrwp577lnejvbaa6/yjMG6detSzfMGt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zr4zKU6t3/ooYemW1Oqba9fvz48/PDDZfLw8Y9/vKybD6rxS8MJAHOvOvjMpTq3P7itweXHH3887Lrrrmmp+6rxS8MJAHOvOvjMpWHbf+aZZ8LSpUvDwoULw9FHHx1WrlyZWkK47bbbwmGHHVYmAZdeemmqff5A2fuYB7d9//33h8WLF6el4X331sXbt9xySzjkkEPCTjvtFD784Q+Hu+++O7VuvH2m5xHve91115WPZ7fddku19Yp9xJKGEwDmXnXwmUvDtn/RRReFU045JTz55JNlgnDGGWeklhD22WefcOutt5ZnEZYvX55qpwxuq1qOH1vcd9994bjjjgvXXHNNWRcN67u3Lt4+8cQTwy9+8YuwZs2acPbZZ4djjjkmtW68fabnUd03fpzy6KOPptp6xT5iScMJAHOvOvjMpWHb33///cMDDzxQ3o4H5T333LO8He21117hqquuCuvWrUs1zxvcVvX4YznqqKPCnXfemVqmDOu7ty7erh5HFC+23HnnndPSxttneh7xvnfddVdamhuxj1jScALA3KsOPnNp2PZ33HHHDQe+WBYsWJBaQnnWIR6UDz744PIjjF6D26qWV6xYUX408L3vfa9crgyuH/XWzbZ9pucRl4clQHWq+k3DCQBzrzr4zKVh299vv/3CqlWr0lIIzz77bLo1JR50r7zyyrD33nunmimD2+pdjmcr4rUH8bqHyi677BJWr16dlkL5EULvfYY9tlHaZ3oew+5bt9hHLGk4AWDuVQefuTRs+8uWLQunnXZaeS3AI488Ek499dTUEsJ5551XHvDvuOOOFyQPixYtKs9GxOshot5tx4RjyZIl4fDDDy8vZIyOPfbY8Ld/+7flNQkxcTj55JP77jPssY3SPtPzGHbfusU+YknDCQBzrzr4zKVh23/66afDWWedVX7UsO+++4Zrr702tYRw2WWXlWcQDjrooHDjjTem2inxbET8FsYee+xRLg9u+/rrry/r4jcgonvvvbf8FkT8psQHPvCB8MMf/rDvPsMe2yjtMz2PYfetW+wjljScADD3qoMPeZI8ANA4yUPeJA8ANE7ykDfJAwCNkzzkTfIAQOMkD3mTPADQOMlD3iQPADRO8pA3yQMAjZM85E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PADRO8pA3yQMAjZM85E3yAEDjJA95kzwA0DjJQ94kDwA0TvKQN8kDAI2TPORN8gBA4yQPeZM8ANA4yUPeJA8ANG6uk4dq+8NKnXq3u/vuu4fTTz89PPbYY6m1u6rnnIYTAOZedfBpQp39HHrooenWlGrb69evDw8//HCZPHz84x8v68Zl8DHOhWr80nACwNyrDj5NqLOfwW0NLj/++ONh1113TUvj0cR+jX3EkoYTAOZedfBpwrB+nnnmmbB06dKwcOHCcPTRR4eVK1emlhBuu+22cNhhh5VJwKWXXppqnz9g9j72wW3ff//9YfHixWlp5n7ifW+88cZwwAEHhPe9733h1FNPDWvWrEmtITz33HPhwgsvDPvss0/5kcinPvWpsHbt2tQ6df/rrruu7G+33XbbUNdb5kq1/TScADD35vrg1mtYPxdddFE45ZRTwpNPPlkmCGeccUZqCeXB+tZbby3PIixfvjzVThncVrUcP7a47777wnHHHReuueaasi6aqZ9435NPPjk8+OCD4dFHHw0nnXRSOPvss1NrCF/4whfCMcccEx566KGwatWqcPzxx4fPfvazqXXq/ieeeGL5cUm8f2XY861b7COWNJwAMPeqg08ThvWz//77hwceeKC8Hd/t77nnnuXtaK+99gpXXXVVWLduXap53uC2qucRy1FHHRXuvPPO1DJlpn7ifWLiUIlnLfbee++0FMKBBx7Yt717772376xGvP9dd92Vlp4X6+da9ZzTcALA3KsOPk0Y1s+OO+644QAYy4IFC1JLKM86xIP+wQcfXH6E0WtwW9XyihUryo8Ovve975XLlZn66b0dxY8kdtppp7Q0dd/4sUcl3u5tj9vblARnLlTPJw0nAMy96uDThGH97LfffuVHAZVnn3023ZoSD8pXXnll35mAaHBbvcvxbEW8tiGeQajM1E+87xNPPJGWQrj99tvDkiVL0lIozzLcfffdaWnqzEM8G1GZbv9NV1+n2EcsaTgBYO5VB58mDOtn2bJl4bTTTiuvFXjkkUfKixUr5513Xli9enW44447XpA8LFq0qDwbEa+HiHq3HROOePA//PDDN5wxmKmfeN9PfvKTZV8x4TjyyCPDFVdckVpDebHkscceu+GahhNOOCFcfvnlqXX6JGHwMc6F2HcsaTgBYO5VB58mDOvn6aefDmeddVb5UcO+++4brr322tQSwmWXXVaeQTjooIPKb0P0imcj4rcw9thjj3J5cNvXX399WRe/YRHN1E9c7+tf/3p5sI/9nX/++X0fQ8QE5Nxzzy37itdhXHDBBeU3MCrT7b/BxzgXYt+xpOEEgLlXHXzms5yfv+QBgMZJHiQPADASyYPkAQBGInnIm+QBgMZJHvImeQCgcZKHvEkeAGic5CFvkgcAGid5yJvkAYDGSR7yJnkAoHGSh7xJHgBonOQhb5IHABonecib5AGAxkke8iZ5AKBxkoe8SR4AaJzkIW+SBwAaJ3nIm+QBgMZJHvImeQCgcZKHvEkeAGic5CFvkgcAGid5yJvkAYDGSR7yJnkAoHGSh7xJHgBonOQhb5IHABonecib5AGAxkke8iZ5AKBxkoe8SR4AaJzkIW+SBwAaJ3nIm+QBgMZJHvImeQCgcZKHvEkeAGhcdfBR8i5pOAFg7k1OTt407GCkZFVuSMMJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAfPGiF/1/W2ooEBvLb3oAAAAASUVORK5CYII=" alt="" width="347" height="334" />
- 一个TestCase的实例就是一个测试用例。什么是测试用例呢?就是一个完整的测试流程,包括测试前准备环境的搭建(setUp),执行测试代码(run),以及测试后环境的还原(tearDown)。元测试(unit test)的本质也就在这里,一个测试用例是一个完整的测试单元,通过运行这个测试单元,可以对某一个问题进行验证。
- 而多个测试用例集合在一起,就是TestSuite,而且TestSuite也可以嵌套TestSuite。
- TestLoader是用来加载TestCase到TestSuite中的,其中有几个loadTestsFrom__()方法,就是从各个地方寻找TestCase,创建它们的实例,然后add到TestSuite中,再返回一个TestSuite实例。
- TextTestRunner是来执行测试用例的,其中的run(test)会执行TestSuite/TestCase中的run(result)方法。
测试的结果会保存到TextTestResult实例中,包括运行了多少测试用例,成功了多少,失败了多少等信息。 - 而对一个测试用例环境的搭建和销毁,是一个fixture。
一个class继承了unittest.TestCase,便是一个测试用例,但如果其中有多个以 test
开头的方法,那么每有一个这样的方法,在load的时候便会生成一个TestCase实例,如:一个class中有四个test_xxx方法,最后在load到suite中时也有四个测试用例。
写好TestCase,然后由TestLoader加载TestCase到TestSuite,然后由TextTestRunner来运行TestSuite,运行的结果保存在TextTestResult中,我们通过命令行或者unittest.main()执行时,main会调用TextTestRunner中的run来执行,或者我们可以直接通过TextTestRunner来执行用例。这里加个说明,在Runner执行时,默认将执行结果输出到控制台,我们可以设置其输出到文件,在文件中查看结果(你可能听说过HTMLTestRunner,是的,通过它可以将结果输出到HTML中,生成漂亮的报告,它跟TextTestRunner是一样的,从名字就能看出来,这个我们后面再说)
用到TestSuite原因:1添加到TestSuite中的case是会按照添加的顺序执行的。2但如果有多个测试文件,怎么进行组织,总不能一个个文件执行吧,答案也在TestSuite中。TestSuite 相当于一个容器,用来装testcase
一:编写测试用例
编写自己的测试用例必须继承TestCase类:class xx(unittest.TestCase):
初始化测试环境:
setUp和tearDown在每次执行case前后都执行了一次。
如果想要在所有case执行之前准备一次环境,并在所有case执行结束之后再清理环境,我们可以用 setUpClass() 与 tearDownClass():
class TestMathFunc(unittest.TestCase):
"""Test mathfuc.py"""
@classmethod
def setUpClass(cls):
"This setUpClass() method only called once."
@classmethod
def tearDownClass(cls):
print
"This tearDownClass() method only called once too."
二:执行测试用例,
执行测试用例有两种方法:
- 若是在测试用例所在的文件内执行用例,直接用 Unittest.main() 方法执行,main()方法会自动执行本文件中所有以test* 命名的函数,
- 如果想将测试用例的文件和执行测试用例的文件分开来执行,需要以下顺序来写执行用例的代码:
A)导入模块:unittest,HTMLTestRunner(或TextTestRunner),测试用例模块
B):suite = unittest.TestSuite() 创建一个名字为suite 的容器,用来装testcase
C):suite.addTest(TestMathFunc(
"test_multi")) 用addTest()方法将case添加容器中 添加的是某一个测试用例
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestMathFunc)) 通过
loadTestsFromTestCase()将case传入TestCase中,添加的是测试类中的所有用例,loadTestsFromModule(module):返回一个给定的模块中所有测试用例,
打包成一个套件返回。该类创建一个testsuites然后加载一个module并执行其中所有的测试用例,,执行的顺序是根据测试用例的名称来的: suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase)
D):1) withopen(
'UnittestTextReport.txt',
'a')
asf:
runner = unittest.TextTestRunner(stream=f, verbosity=
2)
通过TextTestRunner()方法来规定执行的测试用例结果输出到unittestTextReport.txt 文件中
2)
withopen(
'HTMLReport.html',
'w')
asf:
runner = HTMLTestRunner(stream=f,
title=
'MathFunc Test Report',
description=
'generated by HTMLTestRunner.',
verbosity=
2
) 测试用例执行后的输出结果可以通过
TextTestRunner()方法放到指定的txt文件中,或者通过HTMLTestRunner()方法放到指定的html文件中,以网页形式展现,
E):runner.run(suite) 执行用例
3)若在某个目录下写了很多Python文件,每个文件中都有测试测试用例,现在想让这个文件中的所以测试用例都自动执行,需要以下方法:
import unittest,HTMLTestRunner
suite = unittest.TestSuite()#创建测试套件
all_cases = unittest.defaultTestLoader.discover('.','test_*.py')
#找到某个目录下所有的以test开头的Python文件,
for case in all_cases:
suite.addTests(case)#把所有的测试用例添加进来
fp = open('res.html','wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='all_tests',description='所有测试情况')
runner.run(suite)
#运行测试
discover(start_dir, pattern='test*.py',top_level_dir=None)
递归查找指定目录(start_dir)及其子目录下的全部测试模块,将这些测试模块放入一个TestSuite 对象并返回。只有匹配pattern的测试文件才会被加载到TestSuite中。
如果一个测试文件的名称符合pattern,将检查该文件是否包含 load_tests() 函数,如果 load_tests() 函数存在,则由该函数负责加载本文件中的测试用例。如果不存在,就会执行loadTestsFromModule(),查找该文件中派生自TestCase 的类包含的 test 开头的方法。
@unittest.skip("I don't want to run this case.")
def test_divide(self):
"""Test method divide(a, b)"""
"divide"
self.assertEqual(
2, divide(
6,
3))
self.assertEqual(
2.5, divide(
5,
2))
@unittest.skip:此方法用来跳过某个testcase不去执行
Unittest 中的方法:1.检测元素是否相等:assertEqual(a,b [,msg]):检测a==b,这个方法检查a是否等于b,常用语检测元素属性等。assertNotEqual(a,b [,smg]):检测a!==b.
2. 检测表达式是否为Ture,或者 False: assertTrue(x [,msg]) assertFalse(x [,msg])
3. 逻辑运算
assertGreater(a, b) # 检测a > b.
assertGreaterEqual(a ,b) # 检测a >= b.
assertLess(a, b) #检测a < b.
assertLessEqual(a, b) #检测a <= b.=""
<="" code=""></=>
python--unittest测试框架的更多相关文章
- python:unittest(测试框架)
一,基本概念 TestCase:所有测试用例的基类 TestLoad:加载测试用例,返回TestSuite(测试套件) TestSuite:创建测试套件 TextTestRunner:运行测试用例 T ...
- Python 下的unittest测试框架
unittest测试框架,直接上图吧: data:数据:主要格式为CSV:读取方式:csv.reade: public:封装的模块:通用的模块单独封装,所需参数设置为变量: testcase:测试用例 ...
- Python接口测试实战3(下)- unittest测试框架
如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...
- 基于Python的接口自动化-unittest测试框架和ddt数据驱动
引言 在编写接口自动化用例时,我们一般针对一个接口建立一个.py文件,一条接口测试用例封装为一个函数(方法),但是在批量执行的过程中,如果其中一条出错,后面的用例就无法执行,还有在运行大量的接口测试用 ...
- python利用unittest测试框架组织测试用例的5种方法
利用unittest测试框架可以编写测试用例,执行方式分两大类:利用main方法和利用testsuite,其中利用测试套件来组织测试用例可以有4种写法. 在此之前,先了解几个概念 TestCase:所 ...
- python nose测试框架全面介绍十---用例的跳过
又来写nose了,这次主要介绍nose中的用例跳过应用,之前也有介绍,见python nose测试框架全面介绍四,但介绍的不详细.下面详细解析下 nose自带的SkipTest 先看看nose自带的S ...
- <day002>Selenium基本操作+unittest测试框架
任务1:Selenium基本操作 from selenium import webdriver # 通用选择 from selenium.webdriver.common.by import By # ...
- python nose测试框架全面介绍七--日志相关
引: 之前使用nose框架时,一直使用--logging-config的log文件来生成日志,具体的log配置可见之前python nose测试框架全面介绍四. 但使用一段时间后,发出一个问题,生成的 ...
- python nose测试框架全面介绍六--框架函数别名
之前python nose测试框架全面介绍二中介绍了nose框架的基本构成,但在实际应该中我们也会到setup_function等一系列的名字,查看管网后,我们罗列下nose框架中函数的别名 1.pa ...
- python实例编写(6)--引入unittest测试框架,构造测试集批量测试(以微信统一管理平台为例)
---恢复内容开始--- 一.python单元测试实例介绍 unittest框架又叫PyUnit框架,是python的单元测试框架. 先介绍一个普通的单元测试(不用unittest框架)的实例: 首先 ...
随机推荐
- 想入门Web安全,这些基础知识都学会了吗?
毕业季已经正式告一段落,这届毕业生都找到心仪的工作了吗? 正在实习期或者试用期的职场新人,是否在岗位上做的风生水起? 工作了一两年,从未升职加薪的菜鸟,还愿意继续原地踏步吗? 在校学生.IT从业者.毕 ...
- QLineEdit默认提示 setPlaceholderText
Setting this property makes the line edit display a grayed-out placeholder text as long as the text( ...
- liteos信号量(八)
1. 概述 1.1 基本概念 信号量(Semaphore)是一种实现任务间通信的机制,实现任务之间同步或临界资源的互斥访问.常用于协助一组相互竞争的任务来访问临界资源. 在多任务系统中,各任务之间需要 ...
- odoo10学习笔记十三:qweb报表
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/11189336.html 一:概述 报表是使用qweb定义的,报表的pdf导出是使用wkhtmltopdf来完 ...
- 16、基于状态的iptable+高级路由(重点)
-- 基于状态的iptables 如果按照tcp/ip来划分连接状态,有12种之多 但iptables里只有4种状态:ESTABLISHED.NEW.RELATED及INVALID 这两个 ...
- nth-child,nth-of-type
首先,这两个选择器是用来干什么的? 举例子 p:nth-child(1);这个选择器选择的是p所有父辈元素中第一个子元素,且这个子元素为p,此时就生效. p:nth-of-type(1);这个选择器选 ...
- Golang调用Python
https://yq.aliyun.com/articles/117329 Python是时髦的机器学习御用开发语言,Golang是大红大紫的新时代后端开发语言.Python很适合让搞算法的写写模型, ...
- Mybatis ResultMap多表映射DTO
解决问题:n+1问题,之前我的习惯是拿到单表里面的数据,然后遍历,再拿到一个与其他表对应的逻辑上的外键,然后for循环去查找其他表的数据(原因是数据量小,没有在意,还有主要是不想建外键,你知道的,外键 ...
- JDOJ 1044 Span
JDOJ 1044 Span https://neooj.com/oldoj/problem.php?id=1044 Description 某国有N个村子,M条道路,为了实现“村村通工程”现在要”油 ...
- JDOJ 1775: 求N!中0的个数
JDOJ 1775: 求N!中0的个数 JDOJ传送门 Description 求N!结果中末尾0的个数 N! = 1 * 2 * 3 ....... N Input 输入一行,N(0 < N ...