当前位置:网站首页>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()
边栏推荐
- JS基础--数据类型
- Mobile hard drive reads but does not display drive letter
- tmux使用
- JS foundation -- data type
- Handling distributed transactions with powerful dbpack (PHP tutorial)
- node版本管理器nvm安装及切换
- Is it safe to open a stock account online in 2022? Is there any danger?
- The list of winners of the digital collection of "century master" was announced
- flutter Uint8List格式的图片和File格式图片的互相转换
- sdp 协议中的packetization-mode方式和三种流传输模式
猜你喜欢
TEMPEST HDMI泄漏接收 4
Handling distributed transactions with powerful dbpack (PHP tutorial)
Rising Stars in Plant Sciences (RSPS2022) Finalist科学演讲会(6.30晚9点)
NC | 肠道细胞和乳酸菌共同作用来防止念珠菌感染
价值1000毕业设计校园信息发布平台网站源码
Numpy的矩阵
Mall applet source code open source version - two open
Spam filtering challenges
Global filter (processing time format)
Technology sharing | introduction to linkis parameters
随机推荐
银行卡借给别人是否构成犯罪
Valgrind usage of memory leak locating tool
想开个户,在网上开华泰证券的户安全吗?
Intel Labs annonce de nouveaux progrès en photonique intégrée
Uncover the secrets of new products! Yadi Guanneng 3 multi product matrix to meet the travel needs of global users
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.
金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
TEMPEST HDMI泄漏接收 5
Applymiddleware principle
TEMPEST HDMI泄漏接收 3
[encounter Django] - (II) database configuration
Harbor webhook从原理到构建
CVPR22 |CMT:CNN和Transformer的高效结合(开源)
Dotnet console uses microsoft Maui. Getting started with graphics and skia
基金管理人的内部控制
The first anniversary of the data security law, which four major changes are coming?
Database experiment report (I)
CANN算子:利用迭代器高效实现Tensor数据切割分块处理