Unit Test in python


import unittest
unittest 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. The unittest module provides classes that make it easy to support these qualities for a set of tests.

@classmethod is termed as "decorators", decorators function the same way as @test does in TestNG.

 setUpClass()
    A class method called before tests in an individual class run. setUpClass is called with the class as the only argument and must be decorated as a classmethod()

tearDownClass()
    A class method called after tests in an individual class have run. tearDownClass is called with the class as the only argument and must be decorated as a classmethod()

if __name__ == '__main__':
    unittest.main()
Runs the tests the same way you run python code
Note: If the output is Ran 0 tests in 0.000s the run the test as below:
          python -m unittest or python -m unittest -v for verbosity

You can run tests with more detailed information by passing in the verbosity argument:
   if __name__ == '__main__':
     unittest.main(verbosity=2)





Output:

Comments

Popular Posts