Unittest in Python for Dummy

Unittest in Python for Dummy

In this article, we will introduce the following topic for dummy. We are going to answer the following questions.

  • What is unittest?
  • What are available unittest library for python?
  • How to use TestCase class in Python source code?
  • TestSuite for a group of tests
  • HTML test

What is unitTest?

The word “Unit” means break the whole testing suite into testing cases. If we apply it to Web automation, then you will have a testing suite which includes many unit testing scenario. For example –

  • Login
  • Update profile
  • Logout
  • ….

For the selenium/python, we will need unitTest framework to help us to manage these unit testing scenario, execution, verify or assert testing results.

In addition, we may also prepare the testing data or configuration before each unit testing scenario and reset the environment or configuration at the end of each unit testing cases. that’s why we need unitTesting framework here.

 

What are unittesting Framework Available for Python?

 

how to use UnitTesting in Python?

Uses of UnitTesting, your python code structure will look like -
import unittest
...

Class my1stTest(unittest.TestCase):
def setUp(self):
# There is to define configuration, testing data or environment preparation. 
...
...
def test_testCase1(self):
# Define the testing cases execution here.
...
...

def tearDown(self):
# It's to reset the environment or close the browser.
...

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

 

HTML testing Reports

Finally, if we would like the testing results in HTML format. We may use HTMLTestRunner.

For how to use it, refer here.

https://pypi.python.org/pypi/HTMLTestRunner

 

Leave a Reply

Your email address will not be published. Required fields are marked *