Rules on the interface automated testing instructions

Interface Automation Framework total divided into three layers: base layer, api layer, case layer

1. base layer

1.1 helper.py file:

. 1  JsonHelper: The method of extracting information json
 2  MySqlHelper: A method of connecting mysql
 . 3  TimeHelper: time-dependent methods, such as access time or the current time stamp
 . 4  The StringHelper: string-related methods, such as a randomly generated string
 . 5 AllureHelper: the method associated with the allure of Example assertion method.
Common Features

1.2 request.py file: Analog http request

. 1 . 1 . Is encapsulated commonly used methods, and request type http request through the python library requests.
2 2 . Each request message body is returned to a data dictionary, which comprises request parameters, and other parameters in response to the necessary parameters.
3 3. If the http response code is a common error code will throw an exception or exit the program.
http request encapsulated content

1.3 decorators.py file: Define decorator

1  retry_common_api decorator: In some scenarios, may randomly trigger abnormal usage scenarios interface when you call common_api, which will affect the implementation of test cases. Using this decorator, you can capture to a known business exceptions and re-execute this api.
 
2  allure_attach decorator: the Interface of all relevant information processing is returned to the allure for data presented in the report.
 
. 3 wait_until decorator: In some cases, data is written to the database slower operation. When the result in a call query interface, and did not get the desired result. Using this decorator, within the specified time may be fast and flexible query returns the data content.
Decorator Function

2. api layer

api layer can be divided into layers and the Common Base api api layer.

2.1 base layer packages

Rule Description:

Business parameters 1. base layer interface naming conventions: Required Optional _ _ parameter type parameter name

2. For each return label content will use @ allure.step api in order to make the contents of the report presented allure.

Code 3. base layer generally may be automatically generated by the auxiliary tool.

2.2 common encapsulation layer

Rule Description:

1. common api layer inherits api base layer; need to get information from a database as necessary to assist in common encapsulation layer.

2. Each service module corresponds to a py file. common_api.py py file will inherit all business modules, and provided to the case layer use.

3. Each service module interface is divided into three categories: class data submission, data presentation classes, derived classes.

Data Submission categories: interface data is written to the database. Such as add, edit, delete. 
Data presented class: read data to the database interface. Such as a query. 
Derived classes: refining business for the above two types of interfaces. The data submitted in the class has an interface to add personnel, derived class's interface will continue to add people to encapsulate the interface, and then add a package platform administrator, add operations staff, adding the mall staff and other interfaces.
Interface Category Description

4. The interface of each service return code divided into three categories: successful service code, service code known anomalies, abnormal unknown service code.

1  successful business code: By default, all parameter information is returned api request was successful. Also supports accurate return value of a parameter.
2  known in the abnormal traffic code: abnormality information returned default interface. Also supports throw.
3 unknown abnormal traffic code: direct throw.
Interface service code Category Description

The function of the parameter naming convention: a time parameter, a listing category parameter, Editorial parameters, set default parameters

A  time parameter:
 2      the startDateTime: 2019-09-06 00:00:00      # set the default 
. 3      endDateTime: 2019-09-06 23:59:59       # set the default             
. 4      startDate: 2019-09-06
 . 5      endTime: 23 is : 59: 59
 . 6  
. 7  lists the parameters to the interface classes beginning list_
 . 8      list_pageNo         # list page, as the default. 1 
. 9      list_pageSize         # list page size, default is 20 is 
10      list_order         # sorted list 
. 11  
12 is  Editorial interfaces: 
 13      to edit_ interface parameters at the beginning of the parameters that can be edited on behalf of
 14      default parameter values can be edited or details of the interface from the interface list information
Parameter name specification

2.3 api application scene description

1. Scene 1: as interface to the field level calibration parameters

    Usage: In the case of direct call function layer base_api.py file under layer api

2. Scene 2: Reverse service use case

    Usage: In the case of direct call function layer common_api.py api file under layer, and the parameter business_exception = False.

3. Scenario 3: Forward with embodiments of business use cases or precondition

    Usage: In the case of direct call function layer common_api.py api file under layer, and the parameter business_exception = True. In this case a modified retry_common_api decorators, the interface may exclude known abnormal traffic interference test.

3. case layer

3.1 with the design rules described in Example

1. Use Example hierarchical set: field level into use case, the module level use cases, scenarios.

2. The test case within the hierarchical: to implement hierarchical testing procedure by allure.step comment.

3. Each use case must allure of feature, story label, label description is added according to the situation.

4. Example naming function name: test_ embodiment with header.

Example 5. Level divided into three categories: blocker, normal, minor.

3.2 multiplexing step by the method of Example

1. Multiplexing preconditions: Test interface possible dependence is solved by the fixture or pytest conftest.

2. postcondition multiplexing: a high frequency of use case step, the individually packaged in utils. Naming: positive_ * and negative_ *

3.3 Considerations

Example 1. The degree of coupling with a test point as low as possible, with a lot of cases not involving test point

2. For complex interfaces need to make the appropriate split. Ensure the readability and maintainability of the use case

3. Based on the pre-condition module level, the need for rational design.

4. Accessibility

4.1 template code automatically generated api layer.

1. First, write yaml file interface information in yaml_dir directory.

2. assist command execution, copies the temporary area code to the desired position.

4.2 parameterized business data

1. The service data into fixed service parameters and service parameters random.

2. Fixed service data: store in testdata / fixed_businessData.py

3. The random data service: stored in testdata / gen_businessData.py

Guess you like

Origin www.cnblogs.com/reconova-56/p/11485824.html