当前位置:网站首页>三、unittest测试用例五种运行方式
三、unittest测试用例五种运行方式
2022-07-25 09:27:00 【圣诞礼盒】
TestCase用法:
import os
import unittest
class EcshopLogin(unittest.TestCase):
#测试用例
def test01_xiaoming(self):
print("测试小明")
# 测试用例
def test02_weiwei(self):
print("测试微微")
# 测试用例
def test10_xiaohongi(self):
print("测试小红")
if __name__ =='__main__':
suite = unittest.TestSuite()
testcase = unittest.defaultTestLoader.discover(start_dir=os.getcwd(),pattern='*.py')
suite.addTests(testcase)
unittest.main(defaultTest='suite')
#unittest.TextTestRunner().run(suite)两个调用方法结果相同没有区别1.命令行运行方式:python -m unittest -v ecshop_login.EcshopLogin -k *_weiwei
python -m 以脚本的方式去运行一个门模块
python -v --version 意思是更详细的输出结果
ecshop_login.EcshopLogin 模块名.类名.方法名
-k匹配模式:
1.通配符:-k *_weiwei
2.字符串:-k weiwei
适合集成jenkins的时候使用,所有的命令行的方式都叫非GUI的方式
postman:非GUI,newman
jmeter:jmeter的命令
2.使用unittest.main方法,以模块的方式运行
配置pycharm的环境,或者使用python 模块名.py方式运行
if __name__ =='__main__':
print('__________')
unittest.main()读懂执行的结果:
. 成功
F 失败 self.assertTrue(0)
E 错误 raise Exception(”自定义异常”)
S 跳过 @unittest.skip("此用例不执行")
用例执行顺序:
按照ASCLL码的规则:【0-9 A-Z a-z】A=65, a=97
所以用例命名以01-09,在10-99
框架底层原理:
module='__main__', 测试用例所在的路劲 __main__表示当前模块 defaultTest=None, 待测用例的名称,默认是所有 例:defaultTest=["EcshopLogin.test01_xiaoming"] 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
只运行部分用例使用什么测试套件:
3.单个用例:
if __name__ =='__main__':
suite = unittest.TestSuite()
suite.addTest(EcshopLogin("test01_xiaoming"))
suite.addTest(EcshopLogin("test02_weiwei"))
#unittest.main(defaultTest='suite')两个调用方法结果相同没有区别
unittest.TextTestRunner().run(suite)4.用例集:
if __name__ =='__main__':
suite = unittest.TestSuite()
testcase = [EcshopLogin("test01_xiaoming"),EcshopLogin("test10_xiaohongi")]
suite.addTests(testcase)
unittest.main(defaultTest='suite')5.文件下以.py结尾所有用例:
#print(os.getcwd())获取路径
if __name__ =='__main__':
suite = unittest.TestSuite()
testcase =unittest.defaultTestLoader.discover(start_dir=os.getcwd(),pattern='*.py')
suite.addTests(testcase)
unittest.main(defaultTest='suite')边栏推荐
- C3D模型pytorch源码逐句详析(二)
- [nearly 10000 words dry goods] don't let your resume don't match your talent -- teach you to make the most suitable resume by hand
- oracle 解析同名xml 问题
- Rest使用与原理
- Wechat applet jumps to other applets
- JSP详解
- 数论--负进制转换
- 1、 Initial mysql, MySQL installation, environment configuration, initialization
- 记录一些JS工具函数
- CentOS install redis
猜你喜欢

OSPF协议的配置(以华为eNSP为例)

将 conda 虚拟环境 env 加入 jupyter kernel

ROS distributed operation -- launch file starts nodes on multiple machines

线程池的设计和原理

UE4 窗口控制(最大化 最小化)

切换 shell 命令行终端(bash/zsh)后,conda 无法使用: command not found

Trojaning Attack on Neural Networks 论文阅读笔记

mysql历史数据补充新数据

conda 配置深度学习环境 pytorch transformers

nodejs链接mysql报错:ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE
随机推荐
异常处理Exception
SSM整合(简单的图书管理系统来整合SSM)
JSONObject解析json格式的终极总结
IO流中的输入流
Redis和MongoDB的区别
Configuring ROS development environment with vscode: Causes and solutions to the problem of ineffective code modification
Loam transformtoend function integrating IMU details
Download and installation of QT 6.2
【无标题】
修改mysql的分组报错Expression #1 of SELECT list is not in GROUP
腾讯云之错误[100007] this env is not enable anonymous login
GCD详解
力扣刷题组合问题总结(回溯)
动态规划,购物单问题
The way of code neatness -- hit the pain point directly
SSM integration (simple library management system to integrate SSM)
构建 Dompteur 容器问题小记
小程序H5获取手机号方案
[recommended collection] with these learning methods, I joined the world's top 500 - the "fantastic skills and extravagance" in the Internet age
ThreadLocal&Fork/Join