Joke Collection Website - Talk about mood - YApi combined with xxl-job automated testing

YApi combined with xxl-job automated testing

YApi aims to provide more elegant interface management services for developers, products and testers. It can help developers to easily create, publish and maintain APIs, including providing a series of visual interface management and automated testing.

The traditional interface automatic testing is expensive, and a large number of projects do not use automatic testing to ensure the quality of interfaces, but only rely on manual testing, which is very unreliable and prone to errors.

In order to solve this problem, YApi developed the automatic test function of visual interfaces, which can be realized by configuring the parameters of each interface and asserting the response. Moreover, most interfaces support Swagger import or import directly from Idea configuration. The efficiency of interface testing is greatly improved.

To use YApi for automatic testing, the first step is to create a test set and an import interface, click Add Set to create, and then import the interface after creation (the same interface can be imported multiple times).

Writing test cases mainly involves two aspects, one is to request parameters, and the other is to assert scripts.

The request parameter can fill the expected string, and YApi also provides Mock parameters and variable parameters. Mock parameters are used to generate random strings, and variable parameters are used to solve the problem that request parameters depend on the return data or parameters of other interfaces.

Every time the Mock parameter is requested, it generates a random string.

YApi provides a powerful variable parameter function. When testing, you can use the parameters of the previous interface or the return value as the parameters of the later interface. Even if there are dependencies between interfaces, it can be easily tested with one click ~

Format: $. {key}。 {params|body}。 {path}

For example, there are two interfaces, namely "Navigation Title" and "Article List".

The article list interface needs to pass a parameter: the current title (id), which needs to be obtained by navigating the return value of the title. At this time, according to the key of the former, find the corresponding id in the parameter input box of the article list. The parameters and return values of the navigation title have the following structure:

The parameters of the item list can be configured as follows:

Where 269.params * * represents the request parameter of the use case with the key value of 269, and $.269. Body represents the return value of the use case with the key value of 269.

If requestBody is in json format, you can also write variable parameters in json, as shown below:

At present, the input parameters of query, body, header and pathParam in yapi already support the function of clicking and selecting. You don't need to fill in the expression yourself, just select the expression to be displayed in the pop-up window. Input options include constants and analog data, and variable selection is also supported in the test set. Specific usage: Click the edit button to open the expression generator, click the required data to create an expression, or you can view the expression results in real time here.

After writing the request parameters, you can write assertions through js scripts to achieve accurate testing. Click Test Edit on the interface use case page.

In the test list, you can see the key of each test case and the function of starting the test and report.

Click Start Test to test one by one according to the parameters defined in the case. If there is a problem with the order, you can drag and adjust it.

After the test is completed, click Report to view the results of this request.

Reference: /p/32202008

/topics/20437