当前位置:网站首页>TestSuite and testrunner in unittest
TestSuite and testrunner in unittest
2022-07-04 14:09:00 【Field test record】
1、Unittest Medium main use TestSuite Add test cases to the test suite , Reuse Testrunner Run test cases , And generate test reports .TestSuite You can specify the test cases to run , than main Function running test cases should be flexible .
2、TestSuite and TestRunner usage
unittest_testsuite_testrunner_demo.py
# Guide pack
import unittest
# Create the class of the test case
class TestSuiteDemo1(unittest.TestCase):
def test01(self):
print(" The test case : Daejeon 03")
def test02(self):
print(" The test case : Daejeon 04")
class TestSuiteDemo2(unittest.TestCase):
def test01(self):
print(" The test case : Daejeon 01")
def test02(self):
print(" The test case : Daejeon 02")
if __name__ == '__main__':
# Run the specified test case method :
# Instantiate the test suite
suite = unittest.TestSuite()
# Add test cases to the test suite
suite.addTest(TestSuiteDemo1('test01'))
# Instantiation test_runner
runner = unittest.TextTestRunner()
# Use runner Run the test suite
runner.run(suite)
Running results : You can see that only the test cases you want to run
3、TestSuite There are three ways to add test cases
1)suite.addTest: Add a single test case
Just look at the example above
2)suite.addTests: Add multiple test cases
# Add multiple test cases
if __name__ == '__main__':
# Run the specified test case method :
# Instantiate the test suite
suite = unittest.TestSuite()
# Add test cases to the test suite : Add a single test case method
# suite.addTest(TestSuiteDemo1('test01'))
# Add multiple test cases
suite.addTests([TestSuiteDemo2('test01'),TestSuiteDemo2('test02')])
# Instantiation test_runner
runner = unittest.TextTestRunner()
# Use runner Run the test suite
runner.run(suite)
Running results :
3)TestLoader
unittest_testloader_demo.py
import unittest
def testXX(aa):
print(" Extra test cases ")
class TestSuiteDemo1(unittest.TestCase):
def test01(self):
print(" Execute test case aaaa")
def test02(self):
print(" Execute test case bbbb")
class TestSuiteDemo2(unittest.TestCase):
def test01(self):
print(" Execute test case xxxx")
def test02(self):
print(" Execute test case yyyy")
class TestSuiteDemo3(unittest.TestCase):
def test01(self):
print(" Perform interface tests ")
def test02(self):
print(" Perform unit tests ")
def test03(self):
print(" Perform safety test ")
if __name__ == '__main__':
t1 = unittest.TestLoader()
# Method 1
suite = t1.discover("./", "*.py") # Use discover To find test cases
# Method 2
# suite = t1.loadTestsFromTestCase(TestSuiteDemo3)
runner = unittest.runner.TextTestRunner() # Instantiation runner
runner.run(suite) # Use runner Execute test suite
边栏推荐
- Go 语言入门很简单:Go 实现凯撒密码
- IP 实验室月复盘 · 第 5 期
- qt 怎么检测鼠标在不在某个控件上
- Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
- 使用默认路由作为指向Internet的路由
- 2022年起重机械指挥考试模拟100题模拟考试平台操作
- Source code compilation and installation of MySQL
- MySQL 5 installation and modification free
- [antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
- 安装Mysql
猜你喜欢
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
Getting started with the go language is simple: go implements the Caesar password
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
Source code compilation and installation of MySQL
Summary of recent days (non-technical article)
392. Judgement subsequence
随机推荐
逆向调试入门-PE结构-资源表07/07
Go 语言入门很简单:Go 实现凯撒密码
golang fmt.printf()(转)
.Net之延迟队列
FS7867S是一款应用于数字系统供电电源电压监控的电压检测芯片
2022 practice questions and mock exams for the main principals of hazardous chemical business units
动画与过渡效果
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
MySQL8版本免安装步骤教程
Variable promotion and function promotion in JS
以房抵债能否排除强制执行
Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
PHP log debugging
程序员转方向
go vendor 项目迁移到 mod 项目
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
国内酒店交易DDD应用与实践——代码篇
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
读取 Excel 表数据
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)