Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement Unit Test in Pyhon

Shulou Source: shulou.com Published: 2022-06-01 11:43:12 09月26日 Update

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.

Tags: Tests articles units more good practical content additions files articles knowledge calculators references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi Microsoft Shulou Technology Shulou Information