Pyhon Learning: testing calculator classes
The file name is: calculator.py
# calculator class
Class Count: def _ init__ (self,a,b): self.a=int (a) self.b=int (b) # addition def add (self): return self.a+self.b
The test file is: test_cal.py
From calculator import Countclass TestCount: def test_add (self): j=Count (2je 3) add=j.add () assert (5==add), 'Inter addtion result errorships' Except AssertionError as msg: print (msg) else: print ('test pass') # execute the test method; mytest=TestCount () mytest.test_add ()
Unit test: test_cal_1.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 (), 4) def tearDown (self): print ("test end") if _ _ name__ ='_ main__': unittest.main ()