Jmeter does interface testing - interview questions

1. Please explain your overall process of using Jmeter to do interface testing

Using Jmeter for interface testing requires at least the following steps:

1. Write interface test cases according to the interface documents provided by the development

2. Use JMeter to do interface testing, add thread groups and HTTP requests, add corresponding ip addresses, port numbers, specific urls of interfaces, request parameters, etc. in HTTP requests

3. Add a response assertion (to determine whether the test passes)

4. Add view result tree (to view input and output parameters)

5. Execute use cases

6. View the results and verify that the interface returns are consistent with expectations

2. If there are dependencies between front and back interfaces, how do you deal with them?

Jmeter implements interface association and needs to use the extractor in the post-processor. Generally, I often use regular expression extractors and json extractors. For example, the interface of a background management system, except for registration and login, basically all interfaces depend on the token value obtained by the login interface, so it is necessary to obtain the value of the token in the login interface and set it as a variable, and the subsequent interface directly calls this variable.

3. What is an assertion? How does Jmeter set assertions?

The function of an assertion is to set an expected result, and then after the test is executed, if the actual result is inconsistent with the expected result, the test fails.

There are several kinds of assertions in Jmeter, and the ones I usually use are response assertions and Json assertions.

Response assertion is to right-click on the thread group or http request--request--assertion--response assertion, enter the item to be checked and compared in the window, for example, the response body contains 200, after setting the assertion, execute the use case, go to Check the result tree. If the actual result is consistent with the expected result, no error will be reported. If the assertion fails, a red error will be reported.

If the data returned by the interface is in Json format, you can also add a Json assertion, such as asserting that the value of a certain Json data is equal to a certain data.

PS: Sometimes there is no error when viewing the result tree, but it does not mean that there is no problem with the test. For example, if the interface returns 200, it may just mean that the interface is connected, but it does not mean that there is no problem with the function. It is necessary to properly set up the assertion method.

4. How does Jmeter achieve parameterization?

Some parameters in the interface cannot submit repeated data, such as registered account number, mobile phone number, etc. If you want the Jmeter script to not report an error no matter how many times it is executed, you need to realize the parameterization of the script.

There are mainly 4 ways:

1、CSV Data Set Config

Added in the configuration element, it is suitable for scenarios with a large range of scene parameters, and it is convenient for users to modify parameter data at any time. The most used scenario is the parameterized user name and password.

PS: Note, to create a CSV file is to create a new xlsx file and save it as a CSV file after all the editing is done, and then do not make any edits, and do not pull the column width of any column, otherwise an error may be reported.

2. Function assistant

It is a function that comes with Jmeter, suitable for scenarios of generating random numbers, such as generating random strings, random dates, random numbers, etc. Generally, the user name (or other parameter names) of the new function interface is entered as a parameter, and the format is written as: user name string +Random numbers/random strings, you can fuzzy query user strings when querying later. For example: first generate a random number parameter random from 1 to 100: ${ _Random(1,100,)} , which can be stored in user-defined variables and user parameters.

Then quote: myname_${random}

3. User-defined variables

Added in the configuration element, it is suitable for scenarios where parameters do not change frequently in the test plan, such as setting host, port number, url, etc. The user-defined variable obtains a value once at startup, and no longer dynamically obtains a value later. For example, the above random function, if the random number needs to change every time when doing a loop, it is not suitable to be placed here, but needs to be placed The random function is stored in user parameters.

4. User parameters

Added in the pre-processor, it is suitable for scenarios where the value range of the parameter is small. Generally, the logged-in user account and password are used as user parameters. Combined with the above, when running a new scene in the loop, it is necessary to put the random function in the user parameter every time the random number changes. For example, myname_${random}, the first cycle may be myname_11, and the second cycle may be myname_99.

5. What is the execution order of Jmeter test components?

Test plan (only one) --> thread group (at least one) --> configuration element --> preprocessor --> timer --> sampler (at least one) --> postprocessor -- ->Assertions-->Listeners (at least one).

6. How does Jmeter connect to the database? In what scene is it used?

When the interface test involves back-end data verification, such as successfully adding a piece of user information, it may not be enough to rely solely on the return value of the interface to make an assertion. At the same time, it is necessary to connect to the database to find the newly added data and extract the corresponding values ​​​​of each field. Come out and make a matching assertion with the data you inserted. If all pass, it can prove that this interface can successfully complete the function of adding a piece of user information.

connection method:

1. Add the MySQL driver jar package

Click the "Browse..." button in the test plan panel to add the JDBC driver. For example, download the mysql-connector-java-8.0.27.jar package and copy it to the Jmeter/lib directory.

2. Add JDBC Request

Thread group --> sampler --> JDBC Request, note that the value of Variable Name of Pool declared in JDBC Connection Configuration should be meaningful and easy to remember, and the subsequent configuration database connection information needs to be filled with exactly the same value. For example, mySql_test is filled here.

Then write scripts in the sql query statement column according to requirements, and the obtained values ​​are called to the external interface.

The parameter name of the external interface call is written in the Variable names text box, such as loginName.

3. Configure database connection information

Test Plan-->Thread Group-->JDBC Requset-->(Right-click Add) Configuration Component--》JDBC Connection Configuration

in:

3.1 The value of Variable Name for created pool is filled in the same as that of JDBC Request, that is, mySql_test.

3.2 Database URL (database address): jdbc:mysql://ip:port number/database name

3.3 Select the JDBC driver: com.mysql.jdbc.Driver

3.4 Enter the user and password (the user name and password of the database you want to connect to, assuming root/123456)

Guess you like

Origin blog.csdn.net/shuirongwu/article/details/129473847