Assertions in the Appium-unittest framework

Source: Internet
Author: User
Tags appium

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.