Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to sort out the functions in python Unit Test

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you how to organize the functions in the python unit test, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. SetUp prepares the environment.

Prerequisites for executing each test case.

2. TearDown recovers the environment.

Execute the postconditions for each test case.

3. SetUpClass all preconditions executed by case can only be run once.

You must use the @ classmethod decorator

4. TearDownClass only runs once after all case is run.

You must use the @ classmethod decorator

Example

Import unittest# inherits unittest.TestCaseclass CalcTestcase (unittest.TestCase): def setUp (self)-> None: print ("I am setUp") def test01 (self): print ("I am test method test01") def test02 (self): print ("I am test method test02") def test03 (self): print ("I am test method test03") def tearDown ( Self)-> None: print ("I am tearDown") @ classmethod def setUpClass (cls)-> None: print ("I am setUpClass") @ classmethod def tearDownClass (cls)-> None: print ("I am tearDownClass") if _ _ name__ = ='_ _ main__': unittest.main () # setup kit # suite = unittest.TestSuite () # # add test methods to the collection Then loop the value, add it to the suite and output # list = ["test01", "test02", "test03"] # for i in list: # suite.addTest (CalcTestcase (I)) the above is how to clean up the functions in the python unit test. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report