当前位置:网站首页>Unittest-单元测试2
Unittest-单元测试2
2022-04-22 16:09:00 【Skap_W】
续接Unittest-单元测试的记录
六、TestCase用法
import unittest
class EcshopLogin(unittest.TestCase):
#测试用例
def test01_cs(self):
print("测试")
1.使用unittest命令行的方式运行:
python -m unittest -v ecshop_login.EschopLogin
Python -m 以脚本的方式去运行一个模块
Unittest -v --verbose意思就是更详细的输出结果
Ecshop_login.EcshopLogin 模块名.类名.方法名
-k匹配模式:
1.通配符:-k *_cs
2.字符串:-l cs
集成Jenkins的时候使用。为什么?所有命令行的方式都叫做非GUI的方式。
Postman:非GUI,newman
Jmeter:jmeter的命令
2.使用unittest.main(),以模块的方式运行
配置pycharm的环境或者使用python模块名.py
七、读懂执行的结果
. 成功
F 失败
E 错误
S 跳过
八、用例执行的顺序
按ASCII码的规则:【0-9 A-Z a-z】 A=65 a=97
九、框架底层原理
module='__main__', 测试用例用例所在的路径 __main__表示当前模块
defaultTest=None, 待测用例的名称,默认是所有
argv=None, 接受外部的参数
testRunner=None, 测试运行器,TextTestRunner
testLoader=loader.defaultTestLoader, 指定使用默认的测试用例加载器
exit=True, 是否在测试完成之后结束python程序
verbosity=1, 类似于命令行-v,0,1,2
failfast=None,
catchbreak=None,
buffer=None,
warnings=None, *,
tb_locals=False
只运行部分用例使用testsuite:
if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(EcshopLogin("test01_cs01"))
suite.addTest(EcshopLogin("test01_cs02"))
unittest.main(defaultTest='suite')
# unittest.TextTestRunner().run(suite)
if __name__ == '__main__':
suite = unittest.TestSuite()
testcases = [EcshopLogin("test01_cs01"),EcshopLogin("test01_cs011")]
suite.addTests(testcases)
unittest.main(defaultTest='suite')
if __name__ == '__main__':
suite = unittest.TestSuite()
testcases = unittest.defaultTestLoader.discover(start_dir=os.getcwd(),pattern='*.py')
suite.addTests(testcases)
unittest.main(defaultTest='suite')
十、TestFixture测试夹具,或者测试固件
框架的大纲或者说是架构

import unittest
class MyUnit(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
print("setUpClass:在每个类之前执行一次。如:创建数据库,生成日志对象")
def setUp(self):
print("setUp:测试前的准备工作,如:打开浏览器,加载网页")
def tearDown(self):
print("tearDown:测试用例之后的扫尾工作,如:关闭浏览器")
@classmethod
def tearDownClass(cls) -> None:
print("tearDownClass:在每个类之后执行一次,如:关闭数据库连接,销毁日志对象")
SetUpModule 和tearDownModule可以放在方法外面执行
def setUpModule():
print("模块级的夹具开始")
def tearDownModule():
print("模块级的夹具结束")
今天的个人笔记就到这里!!!!!
版权声明
本文为[Skap_W]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Skap_W/article/details/124337438
边栏推荐
- 4.21总结
- Construction method and process of enterprise level knowledge management (km)
- Redis optimization series (I) building redis master-slave based on docker
- How to reduce the cost of Alibaba cloud international server after website optimization
- NDSM, CHM, DTM, DEM, DSM, cut continuously, but clear
- opencv在图片上画框,画点,写字,画线
- The number of distinct data in the query table count MySQL Oracle takes the specified number
- Sending non-protected broadcast
- 396. Rotation function
- 每周推薦短視頻:存量時代如何重構企業核心競爭力?
猜你喜欢

The number of distinct data in the query table count MySQL Oracle takes the specified number

Niu Ke SQL question brushing record

【acwing】1135. 新年好***(dijkstra+堆优化)

Crystal Chem β-乳球蛋白 ELISA 试剂盒 II说明书

CiteSpace installation and use tutorial

nDSM、CHM、DTM、DEM、DSM,剪不断、却理得清
![2022-4-21 [webrtc application] source code analysis of yangrtc / metartc open source library (III)](/img/a5/2e984494455d5a5127964fb49457d7.png)
2022-4-21 [webrtc application] source code analysis of yangrtc / metartc open source library (III)

思科交换机配置

How to reduce the cost of Alibaba cloud international server after website optimization

3D reconstruction of power conductor based on LIDAR point cloud
随机推荐
设某二叉树采用二叉链表表示(即结点的两个指针分别指示左、右子树),当该二叉树包含k个结点时,其二叉链表结点中必有( )个空的左右指针。
Performance evaluation of rust asynchronous framework
JUC (III) ThreadLocal
Send custom fields using Tencent cloud custom alarm SMS interface
引用拷贝,深拷贝,浅拷贝
Talk about data subcontracting and related tips
mysql 数据库优化
The short video produced by we media is very vague? Teach you three ways to make the video clear
MiniUSB管脚接口引脚定义
Go 语言二维或多维数组 / 切片定义上的小坑
[experience sharing] Why is the green screen displayed after the video picture decoding fails?
【无标题】下单及支付
[Kunpeng training camp] Chongqing 2022 developer competition
Altium designer 生成PCB制作文件及打样流程(以嘉立创商城为例)
【acwing】1135. 新年好***(dijkstra+堆优化)
TCP/IP协议之四TCP协议(上)—理论+实践给你讲清楚
Small pit on the definition of two-dimensional or multi-dimensional array / slice in go language
Abbexa丨3,5-二溴酪氨酸说明书
Short link generator, ADF ly、shorte. st、ouo. io、adfoc. Which is better and what are the differences
基于激光雷达点云的电力导线三维重建