1, first unittest itself is a Python test framework, he has his own rules of use;
2, if using one of the methods, need to introduce, methods:
Import UnitTest
Class Login (UnitTest. TestCase):
It is necessary to introduce unittest, and then declare that the class needs to inherit its testcase in order to access its methods.
3, some of the commonly used methods are the following table
The assertion method provided above (except for assertraises (), Assertraisesregexp () receives the MSG parameter, and if specified, takes the body as a failed error message.
1Try:2 num = input ( "enter a Number: ") 3 Span style= "color: #0000ff;" >assert (num = =), "the number is not 10! "4 except5 print Msg6 print ( "sadly, num not equals to 10")
In the above program, run to the Python exception with the assertion. The Raw_input () method requires the user to enter a number, through Arrsert to determine whether the user input num is equal to 10, through the Python assertionerror type of exception to real catch this exception, MSG receive the exception information and print, note, The exception message structure of MSG is our custom ("The number is not 10!") ) 。
Assertequal (First, second, msg=none)
Determines whether the values of first and second are equal, if not equal, the test fails, and MSG is used to define the exception information thrown after the failure.
Assertnotequal (First, second, msg=none)
Test first and second are not equal, and if they are equal, the test fails. Assertture (Expr,msg=none) assertfalse (expr,msg=none) test expr as Ture (or False)
The following is the new assertion method for n Python version 2.7:
Assertis (First, second, msg=none)
Assertisnot (First, second, msg=none)
The first and second tests are (or are not) the same object.
Assertisnone (expr, Msg=none)
Assertisnotnone (expr, Msg=none)
Test expr Yes (or no) to None
Assertin (First, second, msg=none)
Assertnotin (First, second, msg=none)
The test first is (or is not) in second. Second contains whether first is included.
Assertisinstance (obj, CLS, Msg=none)
Assertnotisinstance (obj, CLS, Msg=none)
Tests an instance of the obj not (or not) CLS.
(obj and CLS can be a class or tuple),
To check their type, use Assertis (type (obj), CLS).
Assertions in the Appium-unittest framework