How to implement Unit Test in Pyhon
This article will explain in detail how to achieve unit testing in Pyhon. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
File calculator.py
# calculator class class Count: def _ _ init__ (self,a,b): self.a=int (a) self.b=int (b) # add def add (self): return self.a+self.b
Test case: test_cal_3.py
From calculator import Countimport unittestclass TestCount (unittest.TestCase): def setup (self): print ("test start") def test_add (self): j=Count (2) self.assertEqual (j.add (), 15) def test_add_1 (self): j=Count (12) self.assertEqual (j.add () 15) def tearDown (self): print ("test end") # if _ _ name__ = ='_ _ main__':# unittest.main () # Construction test set suite = unittest.TestSuite () suite.addTest (TestCount ("test_add_1")) suite.addTest (TestCount ("test_add")) # execution test runner = unittest.TextTestRunner () runner.run (suite) on "how to implement unit testing in Pyhon" is shared here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.