Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use parameterization in python test cases

Shulou Source: shulou.com Published: 2022-06-03 17:26:53 09月11日 Update

Editor to share with you how to use parameterization in python test cases, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Description

1. Multiple test cases have the same code, but the test data are different and the expected results are different.

2. Multiple test cases can be combined into a single test case through parameterization technology.

Example

Import unittestimport random def setUpModule (): print ("setUpModule automatically called") def tearDownModule (): print ("tearDownModule automatically called") def my_sum (a, b): return a + b class my_test1 (unittest.TestCase): def test_001 (self): num1 = my_sum (5,6) # define the variable num1 to get the return value self.assertEqual (num1) of the my_sum function 11) what is stored in # num1 is the actual result, and 11 is the expected result # the actual result is consistent with the expected result, which means that the test case passed # does not match the test case test failure def test_002 (self): num1 = my_sum (0,3) self.assertEqual (num1, 3) def test_003 (self): num1 = my_sum (- 3) 7) self.assertEqual (num1, 4) def test_004 (self): num1 = my_sum (- 4,-20) self.assertEqual (num1,-24) # the test cases above are basically the same, and the data of the test cases are different from the expected results. These are all the contents of the article "how to use parameterization in python test cases". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Tests results parameters different articles representatives content multiple actual data same not much code functions variables just most examples technologies more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker OPPO Reno MySQL Shulou Technology