Skip to content

12. unittest framework

NaveenS edited this page Aug 13, 2019 · 3 revisions

The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages. It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework.

Organizing test code

The basic building blocks of unit testing are test cases — single scenarios that must be set up and checked for correctness. In unittest, test cases are represented by unittest.TestCase instances.

Sample Code:

import unittest
class SampleTest(unittest.TestCase):
    def test_values(self):
        self.assertEqual(50,60)

    def test_string(self):
        self.assertEqual("hello","hello")

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

Once executing the above code. Check the Test Result window.

Test Result Window

Clone this wiki locally