当前位置:网站首页>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 边栏推荐
- 2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
- 1200. 最小绝对差
- Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
- Unittest中的TestSuite和TestRunner
- [antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
- 好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
- Service Mesh的基本模式
- Huahao Zhongtian sprint Technology Innovation Board: perte annuelle de 280 millions de RMB, projet de collecte de fonds de 1,5 milliard de Beida Pharmaceutical est actionnaire
- 基于YOLOv1的口罩佩戴检测
- Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
猜你喜欢

Unity shader learning (3) try to draw a circle

Unittest中的TestSuite和TestRunner

1200. 最小绝对差

Openharmony application development how to create dayu200 previewer

源码编译安装MySQL

Five "potential errors" in embedded programming

Dgraph: large scale dynamic graph dataset

苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?

吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行

Distributed base theory
随机推荐
2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
学习项目是自己找的,成长机会是自己创造的
Animation and transition effects
205. 同构字符串
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
Interviewer: what is the internal implementation of hash data type in redis?
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
2022危险化学品经营单位主要负责人练习题及模拟考试
392. 判断子序列
Can mortgage with housing exclude compulsory execution
Qt如何实现打包,实现EXE分享
Mask wearing detection based on yolov1
源码编译安装MySQL
.Net之延迟队列
How to choose a technology stack for web applications in 2022
Lick the dog until the last one has nothing (state machine)
Gorm 读写分离(转)