当前位置:网站首页>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
边栏推荐
- Install Trinity and solve error reporting
- golang fmt.printf()(转)
- MySQL 5 installation and modification free
- Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
- 担心“断气” 德国正修改《能源安全法》
- 英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
- Test evaluation of software testing
- 使用默认路由作为指向Internet的路由
- OpenHarmony应用开发之如何创建DAYU200预览器
- Install MySQL
猜你喜欢
How to choose a technology stack for web applications in 2022
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
2022危险化学品经营单位主要负责人练习题及模拟考试
Openharmony application development how to create dayu200 previewer
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
392. Judgement subsequence
JVM series - stack and heap, method area day1-2
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators
软件测试之测试评估
随机推荐
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
Worried about "cutting off gas", Germany is revising the energy security law
mac redis安装与使用,连接远程服务器 redis
Idea shortcut keys
SCM polling program framework based on linked list management
硬件基础知识-二极管基础
2022G3锅炉水处理考试题模拟考试题库及模拟考试
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
自主工业软件的创新与发展
Whether the loyalty agreement has legal effect
Install MySQL
qt 怎么检测鼠标在不在某个控件上
Understanding and difference between viewbinding and databinding
Can mortgage with housing exclude compulsory execution
DGraph: 大规模动态图数据集
Unittest框架中引入TestFixture
做事的真正意义和目的,真正想得到什么
【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...