Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the functions in the python unit test

Shulou Source: shulou.com Published: 2022-05-31 10:47:25 09月13日 Update

This article focuses on "what are the functions in python unit testing". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the functions in python unit testing.

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)) so far, I believe you have a deeper understanding of "what are the functions in the python unit test". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Test method function unit yes condition run content suite environment learning practical deeper interest premise example practicality practical simple operation more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple Huawei MySQL Linux