code, software architect, articles and novels. 代码,软件架构,博客和小说
Python Unittest
Posted onEdited onWord count in article: 562Reading time ≈1 mins.
first you should import unittest, and write a class inherit unittest.TestCase. Then write some function named test_XXX, which uses "test_" as its prefix. Then in main, call the class's main() function.
this is an example:
1 2 3 4 5 6 7 8 9 10
import unittest
classTestFunctions(unittest.TestCase): deftest_range(self): for i inrange(10): self.assertEqual(i,i)
if __name__ == "__main__": TestFunctions.main()
In this example, TestFunctions.main() will call all functions like test_XXX between setUp() and tearDown(). The sequence is