Course Content
Testing Tools
Testing Tools
0/1
Sample Python Programs
Sample Python Programs
0/1
Selenium Python First Script
Selenium Python First Script
0/2
HTML Form elements
HTML Form elements
0/1
Handle HTML Frames
Handle HTML Frames
0/2
Handling Dropdown Lists
Handling Dropdown Lists
0/2
Selenium Action class
Selenium Action class
0/1
Python Database Programming
Python Database Programming
0/1
Selenium Python for Beginners [ 2024 ]
About Lesson

@parameterized Test Example

Remember to install the parameterized module using pip before using it in your code.

Example

Here’s an example test to demonstrate how to use parameterization in
Python PyUnit tests:

  • Launch Eclipse IDE.
  • Create a Python script file with the .py extension
  • Add the following code.
  • Run the Python unit test. ( Run As >> Python unit-test )

 

# PyUnit Test Parameterization Example
# www.TestingDocs.com

import unittest
from parameterized import parameterized

class TestParameterization(unittest.TestCase):

    @parameterized.expand([
        (3, 2, 5),
        (5, 5, 10),
        (20, 16, 36)
    ])
    
    
    def test_addition(self, a, b, expected_result):
        result = a + b
        self.assertEqual(result, expected_result)

if __name__ == '__main__':
    unittest.main()

Screenshot

Screenshot in Eclipse IDE.

@parameterized Test Example

 

You can notice that the test runs three times for each test data. 

 

Join the conversation