You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Let'sdiveintocoding-wehavealreadycompletedstep1and2-Let'screateafilecalledcalc_test.py-wewilluse'unittest'and'pytest'-'pip install'-'python -m unittest'-'python -m unittest discover -v'## calc_test.py# let's import unittest and pytest as these are the dependencies and runimportunittestimportpytestfromsimple_calcimportSimpleCalcclassCalctest(unittest.TestCase):
calc=SimpleCalc()
# assertions to write our test cases# we will use our basic calculator example to write the tests first then the codedeftest_add(self):
# Naming convention is essential to have test in the name of our methodself.assertEqual(self.calc.add(3,2), 5) #if True test would pass#return num1 + num2deftest_substract(self):
self.assertEqual(self.calc.subtract(8, 5), 3) # 8 - 5 = 3deftest_multi(self):
self.assertEqual(self.calc.multiply(2, 3), 6) # 2 * 3 = 6deftest_div(self):
self.assertEqual(self.calc.divide(6, 3), 2) # 6 / 3 = 2## simple_calc.pyclassSimpleCalc:
defadd(self, num1, num2):
returnnum1+num2defsubtract(self, num1, num2):
returnnum1-num2defmultiply(self, num1, num2):
returnnum1*num2defdivide(self, num1, num2):
returnnum1/num2