当前位置:网站首页>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
边栏推荐
- Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
- go vendor 项目迁移到 mod 项目
- 2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
- 苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
- 美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
- 吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
- 以房抵债能否排除强制执行
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- 205. 同构字符串
猜你喜欢
基于PaddleX的智能零售柜商品识别
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
Understanding and difference between viewbinding and databinding
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
MySQL version 8 installation Free Tutorial
基于YOLOv1的口罩佩戴检测
面试拆解:系统上线后Cpu使用率飙升如何排查?
MySQL8版本免安装步骤教程
2022年起重机械指挥考试模拟100题模拟考试平台操作
MySQL 5 installation and modification free
随机推荐
Distributed base theory
Summary of recent days (non-technical article)
2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
【C 题集】of Ⅶ
MySQL 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table
Unity shader learning (3) try to draw a circle
SCM polling program framework based on linked list management
MySQL 5 installation and modification free
OPPO Find N2产品形态首曝:补齐各项短板
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
PHP log debugging
Mask wearing detection based on yolov1
Fs4056 800mA charging IC domestic fast charging power IC
如何在 2022 年为 Web 应用程序选择技术堆栈
忠诚协议是否具有法律效力
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
[R language data science]: cross validation and looking back
【R语言数据科学】:交叉验证再回首
CVPR 2022 | greatly reduce the manual annotation required for zero sample learning, and propose category semantic embedding rich in visual information (source code download)
Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme