当前位置:网站首页>[automated testing framework] what you need to know about unittest
[automated testing framework] what you need to know about unittest
2022-07-06 23:52:00 【Test Xiaona】
One 、UnitTest The unit test framework provides those functions
1. Provides use case organization and execution
How to define a “ The test case ”?
How to flexibly control these “ The test case ” Implementation ?
2. Provide abundant assertion methods
When the execution result of the test case is inconsistent with the expected result , Determine that the test case failed . In automated testing , adopt “ Assertion ” To determine whether the test case execution is successful , The testing framework provides rich assertion methods , for example : Judge equal / Unequal inclusion / It doesn't contain 、True/False etc.
3. Provide rich logs
The reason for the failure needs to be clearly seen from the results . in addition , We also need to count the execution results of test cases , Such as total execution time 、 Number of failed test cases 、 Number of successful test cases, etc , These functions are also provided by the unit test framework .
Two 、 know unittest
1. introduce unittest modular , Custom classes must inherit unittest Modular TestCase class
2. Test method created , Must be test start
3. Important concepts
3.1 TestCase
Test Case Is the smallest test unit , A specific return value used to check a specific set of inputs .unittest Provided TestCase The base class is inherited by the custom test class , It can be used to create new test cases
3.2 TestSuite
A test suite is a test case \ Test suite or a collection of both , Used to assemble a set of tests to run
3.3 Test Runner
Test Runner Is a component , Used to coordinate test execution and provide results to users .Test Runner You can use a graphical interface 、 A text interface or a special value is returned to display the results of the test execution
3.4 Test Fixture
Test Fixture Represents the environmental preparation required to perform one or more tests , And associated cleanup actions .
3、 ... and 、 assert methods

Four 、 Organization of test cases
1、unittest Medium TestLoader Class provides the discover() Method can find test cases from multiple files
2、 Find all test modules in the specified directory and its subdirectories , Only matching file names can be loaded , If you are not starting the top-level Directory , Then the top-level directory must be specified separately
discover(start_dir,pattern=’ test*.py’ ,top_level_dir=None)
3、start_dir: Module name or test case directory to be tested
4、pattern= 'test*.py’: Matching principle of test case file name
5、top_level_dir: Top level directory of the test module , If there is no top-level Directory , The default is None
5、 ... and 、 Execution order of test cases
Multiple directories > Multiple test files > Multiple test classes > Multiple test methods
Execute the test case of multi-level directory
unittest The default in accordance with the ASCII Code sequence loading test cases ( The alphabetical and numerical order is 0-9,A-Z,a-z)
Execute multi-level subdirectories to lower one __init__.py file , This file is used to mark a directory as a standard python modular


import unittest
test_dir = './test_case'
suite=unittest.defaultTestLoader.discover(test_dir, pattern='test*.py')
if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(suite)
6、 ... and 、 Skip tests and expected failures

7、 ... and 、 Data driven applications
Installation mode
pip install parameterized
Usage mode
adopt @parameterized.expand() To decorate test cases ,expand Each tuple in is considered a test case , The data in the tuple is the change value of the test case
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it

These materials , For doing 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful …….
If you don't want to experience it again, you can't find information when you study on your own , No one answers the question , If you insist on giving up after a few days , You can add mine below qq Group discussion and Exchange , There are also various software testing materials and technical exchanges .
边栏推荐
- B 站弹幕 protobuf 协议还原分析
- (LeetCode)两数之和
- The tutorial of computer reinstallation win10 system is simple and easy to understand. It can be reinstalled directly without U disk
- 本地部署 zeppelin 0.10.1
- Basic chart interpretation of "Oriental selection" hot out of circle data
- JS import excel & Export Excel
- Where does this "judge the operation type according to the op value and assemble SQL by yourself" mean? It means simply using Flink tab
- MySQL implementation of field segmentation from one line to multiple lines of example code
- Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
- Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work
猜你喜欢

Gradle知識概括

电脑重装系统u盘文件被隐藏要怎么找出来

【精品】pinia 基于插件pinia-plugin-persist的 持久化

leetcode:236. The nearest common ancestor of binary tree

Wu Enda 2022 machine learning course evaluation is coming!

AVL树到底是什么?

app通用功能测试用例

氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!

Please help xampp to do sqlilab is a black

If the request URL contains jsessionid, the solution
随机推荐
B 站弹幕 protobuf 协议还原分析
Wasserstein slim gain with gradient poverty (wsgain-gp) introduction and code implementation -- missing data filling based on generated countermeasure network
Detailed explanation of regular expression (regexp) in MySQL
Basic chart interpretation of "Oriental selection" hot out of circle data
Should the jar package of MySQL CDC be placed in different places in the Flink running mode?
MVC and MVVM
[212] what are three methods for PHP to send post requests
Summary of three methods for MySQL to view table structure
Local deployment Zeppelin 0.10.1
Server SMP, NUMA, MPP system learning notes.
【通信】两层无线 Femtocell 网络上行链路中的最优功率分配附matlab代码
【系统分析师之路】第七章 复盘系统设计(面向服务开发方法)
若依请求url中带有jsessionid的解决办法
DAY ONE
Wasserstein Slim GAIN with Gradient Penalty(WSGAIN-GP)介绍及代码实现——基于生成对抗网络的缺失数据填补
MySQL implementation of field segmentation from one line to multiple lines of example code
【自动化测试框架】关于unittest你需要知道的事
Do you still have to rely on Simba to shout for a new business that is Kwai?
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
Can online reload system software be used safely? Test use experience to share with you