def test_two_positive_sub(self): result = MathMethod(3, 2).subb() expected = 11 try: self.assertEqual(expected, result) except AssertionError as e: print("这是个断言错误{}".format(e)) raise e print("两个正数相减的值是{},预期结果是{}".format(result, expected))
def test_abs_positive_negitve(self): #第一条执行的用例 result = MathMethod(2, -5).a_b_s() excepted = 7 try: self.assertEqual(result, excepted) except AssertionError as e: print("出现断言错误", e) raise e print("一正一负两个数相减的绝对值是:{}".format(result))
def test_abs_two_negtive(self): #第二条执行的用例 result = MathMethod(-2, -5).a_b_s() expected = 3 try: self.assertEqual(result, expected) except AssertionError as e: print("出现断言错误", e) raise e print("两个负数相减的绝对值是:{}".format(result))
def test_abs_two_positive(self): #第三条执行的用例 result = MathMethod(2, 3).a_b_s() expected = 1 try: TestAbs().assertEqual(result, expected) except AssertionError as e: print("出现断言错误", e) raise e print("两个正数相减的绝对值是:{}".format(result))
def test_positive_negtive_sub(self): result = MathMethod(2, -4).subb() expected = 6 try: self.assertEqual(expected, result) except AssertionError as e: print("这是个断言错误{}".format(e)) raise e print("一正一负相减的值是{},预期结果是{}".format(result, expected))
def test_add_negtive_positive(self): #一正一负相加 result = MathMethod(-1, 3).add() expected = 2 try: self.assertEqual(expected, result) #断言 except AssertionError as e: print("断言出错{}".format(e)) raise e print("一正一负相加的结果是:{}".format(result))
def test_add_two_negtive(self): #两个负数相加 result = MathMethod(-1, -3).add() # expected = 1 try: self.assertIsNotNone(result) # self.assertEqual(expected,result) #断言 except AssertionError as e: print("断言出错{}".format(e)) raise e print("两个负数相加的结果是:{}".format(result))
def test_add_two_zero(self): #必须以test开头,不能传参 result = MathMethod(0, 0).add() #两个0相加 expected = 0 #(期望结果) try: # self.assertTrue(result) self.assertEqual(expected, result) #断言 # self.assertFalse(result) except AssertionError as e: print("断言出错{}".format(e)) #处理 raise e #抛出异常,否则不抛出直接执行,有异常时已经处理了就显示通过了 print("两个0相加的结果是:{}".format(result))