当前位置:网站首页>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
边栏推荐
- Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
- 嵌入式编程中五个必探的“潜在错误”
- 1200. Minimum absolute difference
- 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
- qt 怎么检测鼠标在不在某个控件上
- SCM polling program framework based on linked list management
- Animation and transition effects
- Idea shortcut keys
- 程序员转方向
- sharding key type not supported
猜你喜欢
OPPO Find N2产品形态首曝:补齐各项短板
动画与过渡效果
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
Automatic filling of database public fields
源码编译安装MySQL
分布式BASE理论
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
Test evaluation of software testing
Distributed base theory
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
随机推荐
Openharmony application development how to create dayu200 previewer
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
php 日志调试
Unity shader learning (3) try to draw a circle
分布式BASE理论
动画与过渡效果
2022年起重机械指挥考试模拟100题模拟考试平台操作
WS2811 M是三通道LED驱动控制专用电路彩灯带方案开发
MySQL 5 installation and modification free
Haproxy high availability solution
[C question set] of VII
Detailed explanation of Fisher information quantity detection countermeasure sample code
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
.Net之延迟队列
WS2818M是CPC8封装,是三通道LED驱动控制专用电路外置IC全彩双信号5V32灯可编程led灯带户外工程
Five "potential errors" in embedded programming
做事的真正意义和目的,真正想得到什么
PHP log debugging