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 use parameterization in python test cases

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

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!

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