Assertequals
Function prototype 1: assertequals ([String message],expected,actual)
Parameter description:
The message is optional and, if provided, will be reported when an error occurs.
expected are expected and are typically user-specified content.
actual is the actual value returned by the code being tested.
function prototype 2:assertequals ([String message],expected,actual,tolerance)
Parameter description:
The message is optional and, if provided, will be reported when an error occurs.
Expected are expected and are typically user-specified content.
Actual is the actual value returned by the code being tested.
Tolerance is the error parameter, and the two floating-point numbers participating in the comparison are considered
Equal.
Example:
#定义被测方法, file name is wait_test.py
def add (A, B):
Return a+b
Def Cheng (A, B):
Return a*b
---------------------------------
Import UnitTest
From wait_test Import *
Class MyTest (UnitTest. TestCase):
def test_add (self):
#断言
Self.assertequal (8,add (3,5), ' error ')
def Test_cheng (self):
Self.assertequal (15,cheng (3,5), ' error ')
if __name__ = = ' __main__ ':
Unittest.main ()
The first knowledge of Python's unittest