Course Content
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
Selenium Python for Beginners [ 2024 ]
About Lesson

PyUnit Example

You will create and run your first PyUnit test using an IDE in this lesson. Let’s run a sample PyUnit test using Eclipse IDE. Follow the below steps:

Create Python Test

Launch Eclipse IDE.

Create a new PyUnit test File >> New >> File

Give a name to the test.

The filename should have a .py extension.

For example, myfirsttest.py

Add the following code:

# Python Unit Test Example
# Python Tutorials - www.TestingDocs.com

import unittest

class MyTestCase(unittest.TestCase):
    def test_example(self):
        self.assertEqual(7 + 9, 16)


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

 

Run Python Test

Save the code. Choose the following menu option to save the test.

File >> Save The keyboard shortcut is the Ctrl + S key combination.

Run the test.

Right-click on the test and choose

Run As >> Python unit-test option.  

 

Python unit test Run As

 

Test Output

The graphical output console is the PyUnit Console, which displays green or red if the test is passed or failed.

The following output should be displayed in the console:

Ran 1 test in 0.000s

OK

This means that one test has run and passed.

The output will also display the time the test(s) took to run.  

 

Python Unit Test Output EclipseIDE

Join the conversation