This project has some examples on how to write simple unittest in python.
It covers the basic topics like:
- setUp and tearDown
- assertion
- skipping tests
- using mocks
- example for testing with and without a framework (see id_creator)
It is possible to run all tests in the project or be more specific and even run one single testcase. Below are some examples on the different ways of running the tests:
python3 -m unittest
python3 -m unittest test_assertions
python3 -m unittest test_assertions.TestAssertions
python3 -m unittest test_assertions.TestAssertions.test_equality
It is also possible to use the build in function from unittest and run the tests by creating following function:
if __name__ == '__main__':
unittest.main()
See test_setup_teardown.py