斷言
阿新 • • 發佈:2020-06-28
import unittest import random class MyClass(object): @classmethod def sum(cls,a,b): return a+b @classmethod def div(cls,a,b): return a/b @classmethod def return_None(cls): return None class MyTest(unittest.TestCase): def test_assertEqual(self):#相等 try: a,b=1,2 sum = 13 self.assertEqual(a+b,sum) except AssertionError as e: print(e) def test_assertNotEqual(self): #不相等 try: a,b=4,2 div=4 self.assertNotEqual(a/b,div)except AssertionError as e: print(e) def test_assertFalse(self): #假 try: self.assertFalse(1==2) except AssertionError as e: print(e) def test_assertTrue(self): #真 try: self.assertTrue(1==1) exceptAssertionError as e: print(e) def test_assertIs(self): try: a=1 b=a self.assertIs(a,b) except AssertionError as e: print(e) if __name__=='__main__': unittest.main()