当前位置:网站首页>Unittest 框架介绍及第一个demo
Unittest 框架介绍及第一个demo
2022-07-01 11:07:00 【大田测试录】
1、作用:管理测试用例、断言、生成测试报告
2、Unittest官网文档:看语法和用法,用法也可以看网上教程
unittest — Unit testing framework — Python 3.10.5 documentation
3、组成部分
test fixture:测试固定组件
test case:测试用例,执行测试的最小单元
test suite:测试套件,它是一个用例集,用来汇总应该一起执行的测试用例
test runner:测试运行器,是设计测试执行方式的元件,提供了输出结果的展现方式,可以用图标、文本、html方式来展现测试结果

TestFixture融合在代码中运行,体现在TestCase中
4、unittest在python3中,是python的内置模块了,无需安装就能使用
实例:

5、修改运行方式
1)上图是默认unittest执行方式

默认运行方式可以选择以下几种:
2)普通模式执行
选择edit configuration


加号内容选择看上一图即可

apply之后呢,看页面中右上角执行方式就改为了普通模式执行

上图中在执行2下方有两个点,证明执行成功
E代表执行错误,脚本写错了程序写错
F代表执行失败
6、unittest运行时,应注意的点
Unittest 运行的测试用例,必须是继承了TestCase方法,并且这个方法默认以test开头,默认执行顺序是在test之后的字符按照ASCII码大小执行
# 导包
import unittest
# 创建继承unittest.TestCase的类
class FirstDemo(unittest.TestCase):
#创建测试用例
def test01(self):
print("执行1")
def test02(self):
print("执行2")
if __name__ == '__main__':
unittest.main()
边栏推荐
- [paper reading] trajectory guided control prediction for end to end autonomous driving: a simple yet strong Ba
- Can I choose to open an account on CICC securities? Is it safe?
- Spam filtering challenges
- 商城小程序源码开源版-可二开
- [AI information monthly] 350 + resources! All the information and trends that can't be missed in June are here! < Download attached >
- Handling distributed transactions with powerful dbpack (PHP tutorial)
- The exclusive collection of China lunar exploration project is limited to sale!
- Give up high paying jobs in Shenzhen and go back home
- Have the bosses ever done the operation of sink shunting and writing to Clickhouse or other databases.
- 软件项目管理 9.2.软件项目配置管理过程
猜你喜欢
![[AI information monthly] 350 + resources! All the information and trends that can't be missed in June are here! < Download attached >](/img/62/562e93e66addc8e86c0a19bc514389.png)
[AI information monthly] 350 + resources! All the information and trends that can't be missed in June are here! < Download attached >

Combination of Oracle and JSON

Database experiment report (I)

Huawei equipment is configured with large network WLAN basic services

Face detection and recognition system based on mtcnn+facenet

The project bar on the left side of CodeBlocks disappears, workspace automatically saves the project, default workspace, open the last workspace, workspace (Graphic tutorial, solved)

Addition, deletion, modification and query of database

Technology sharing | introduction to linkis parameters

我国蜂窝物联网用户已达 15.9 亿,年内有望超越移动电话用户

Value 1000 graduation project campus information publishing platform website source code
随机推荐
Submission lottery - light application server essay solicitation activity (may) award announcement
我国蜂窝物联网用户已达 15.9 亿,年内有望超越移动电话用户
全局过滤器(处理时间格式)
Mysql的四个隔离级别是如何实现的 (简要)
达梦数据冲刺科创板:拟募资24亿 冯裕才曾为华科教授
华为设备配置大型网络WLAN基本业务
China's cellular Internet of things users have reached 1.59 billion, and are expected to surpass mobile phone users within this year
The exclusive collection of China lunar exploration project is limited to sale!
y48.第三章 Kubernetes从入门到精通 -- Pod的状态和探针(二一)
Intel Labs annonce de nouveaux progrès en photonique intégrée
优雅地翻转数组
Technology sharing | introduction to linkis parameters
Valgrind usage of memory leak locating tool
MIT最新论文《对可解释特征的需求:动机和分类》:在机器学习模型的组成元素中建立可解释性
Database experiment report (I)
Neurips 2022 | cell image segmentation competition officially launched!
[encounter Django] - (II) database configuration
8款最佳实践,保护你的 IaC 安全!
NeurIPS 2022 | 细胞图像分割竞赛正式启动!
商城小程序源码开源版-可二开