API test implementation method based on JMeter

Writing automated API test scripts and configuration jobs through JMeter solves the problem of incomplete functional interface testing of cloud platform service products, achieves comprehensive coverage testing of cloud platform service product functions, supports multiple architectures and environments, saves labor costs, and simplifies testing process to improve testing efficiency and accuracy.

CN118820091APending Publication Date: 2024-10-22SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410877038.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-10-22

AI Technical Summary

Technical Problem

Existing technology cannot conduct complete and comprehensive testing of all functional interfaces in cloud platform service products, resulting in incomplete API testing.

Method used

Adopt the JMeter-based API testing method by writing automated test scripts and API test scripts, uploading them to the cloud platform environment, configuring the Job, and creating the Job through apply apitest.yaml, automatically executing the API test, and viewing the test results to locate problems.

Benefits of technology

It achieves comprehensive coverage testing of cloud platform service product functions, supports multiple architectures and environments, saves labor costs, simplifies the testing process, and improves testing efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118820091A_ABST
    Figure CN118820091A_ABST
Patent Text Reader

Abstract

The invention discloses an API test implementation method based on JMeter, and relates to the field of automatic testing. Comprising the steps of 1, compiling an automatic test JMeter script, and compiling an API test script according to functions of a service product; 2, performing test pre-preparation; 3, configuring a Job for operating the automatic test JMeter script and the API test script on a cloud platform in a Job form; 4, creating the Job through application apitest.yaml in an environment, calling the API test script according to pre-configuration, and performing automatic test on the environment. And 5, checking the test result: storing the API test result in a timestamp directory, summarizing the passing rates of executed scripts, checking the number of failed use cases and the passing rates of API test of each service product, and carrying out problem positioning and troubleshooting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention discloses a method, which relates to the field of automated testing, and specifically is a JMeter-based API testing implementation method. Background Art

[0002] The service products of cloud platforms mainly refer to cloud computing products provided as services, and the corresponding service products of cloud platforms usually provide functional interfaces for calling service products. For functional interfaces, functional interface testing is required to ensure that the functional interfaces can realize their functions, but the current testing methods usually cannot target all functional interfaces in service products, so API testing is not complete and comprehensive. Summary of the invention

[0003] In view of the problems of the prior art, the present invention provides a JMeter-based API testing implementation method, which has the characteristics of strong versatility, simple implementation, etc. and has broad application prospects.

[0004] The specific scheme proposed by the present invention is:

[0005] The present invention provides a JMeter-based API test implementation method, comprising:

[0006] Step 1: Write an automated test JMeter script and write an API test script based on the functions of the service product:

[0007] Step 2: Test pre-preparation, upload the API test related files of the automated test JMeter script and API test script to the cloud platform environment, select the node to upload according to the execution environment, check whether the container image exists in the environment, if not, upload the container image to the environment and push it to the image warehouse,

[0008] Step 3: Configure a Job to run the automated test JMeter script and API test script in the cloud platform as a Job: extract the parameters used by the automated test JMeter script and put them into the environment variables of the Job Pod, configure multiple API test scripts, and sort the script execution order.

[0009] Step 4: Create a Job by applying apitest.yaml in the environment, call the API test script according to the pre-configuration, and perform automated testing on the environment.

[0010] Step 5: View test results: API test results are stored in the timestamp directory, summarizing the pass rate of the executed scripts. View the number of failed test cases and pass rate of each service product API test to locate and troubleshoot problems.

[0011] Furthermore, in the JMeter-based API test implementation method, writing an automated test JMeter script in step 1 includes:

[0012] According to the thread group, request and listener of the JMeter script, set the loop and number of threads through the thread group, configure the request address, protocol and parameters through the Sampler, and monitor the request and response content through the listener.

[0013] Execute Jmeter components according to the configuration primitives, pre-processors, timers, samplers, post-processors, assertions, and listeners.

[0014] Further, in the JMeter-based API test implementation method, writing an API test script in step 1 includes:

[0015] Identify common parameters in service products for subsequent configuration in Jobs.

[0016] Use Chinese identifiers for the test names of API test script interfaces to facilitate test result output.

[0017] Extract the variable value in HTTPSampler.path value as a parameter to facilitate use on different cloud platforms.

[0018] Furthermore, in step 2 of the JMeter-based API test implementation method, the API test related files are placed in the / home / apitest directory. According to the directory structure, apitest.yaml is the file that defines the JMeter Job, the jmxScript folder stores the API test script of the service product, and runjmx.sh is the script file executed when the JMeter container is started.

[0019] Furthermore, in step 3 of the JMeter-based API test implementation method, for an environment with the same cloud platform version but different service products, the env part in apitest.yaml is modified, and the environment variables are replaced in the runjmx.sh script. If new parameters need to be added, the variables are extracted from the API test script, a set of parameters and default values ​​are added to env according to the example, and the parameters are replaced in runjmx.sh.

[0020] Furthermore, in the JMeter-based API test implementation method, the Job in step 4 is executed on the master node by default. If it is executed on other nodes, it is modified to other nodes, and the pre-configured API test script is called to perform automated testing on the environment.

[0021] Furthermore, the detailed results of the corresponding API test results in step 5 of the JMeter-based API test implementation method are stored in the jmx directory corresponding to the timestamp directory, the csv file records the interface test results of each service product, the log file records the execution log of JMeter, and the reports directory records the Dashboard of the test results of each service product, which displays the test status in the form of charts, and the index.html file is checked to obtain the specific results of the JMeter script execution.

[0022] The present invention also provides a JMeter-based API test implementation device, including a script management module, a pre-preparation module, a Job configuration module, a test module and a query display module.

[0023] The script management module writes automated test JMeter scripts and writes API test scripts based on the functions of the service products:

[0024] The pre-preparation module tests the pre-preparation, uploads the API test related files of the automated test JMeter script and the API test script to the cloud platform environment, selects the node to upload according to the execution environment, checks whether the container image exists in the environment, and if not, uploads the container image to the environment and pushes it to the image warehouse.

[0025] The Job configuration module configures the Job, which is used to run the automated test JMeter script and API test script in the cloud platform in the form of a Job: extract the parameters used by the automated test JMeter script and put them into the environment variables of the Job Pod, configure multiple API test scripts, and sort the script execution order.

[0026] The test module creates a Job by applying apitest.yaml in the environment, calls the API test script according to the pre-configuration, and performs automated testing on the environment.

[0027] Query the display module to view test results: API test results are stored in a timestamp directory, summarizing the pass rate of the executed scripts. You can view the number of failed cases and pass rate of each service product API test to locate and troubleshoot problems.

[0028] The benefits of the present invention are:

[0029] Supports regular functional testing of cloud platform service products: The functions of cloud platform service products can be tested by writing test scripts. When a new version of a service product is released, the test scripts are also relatively iteratively maintained to ensure comprehensive coverage of functional use cases. Test cases can be continuously adjusted to adapt to functional changes and can be executed in different environments to verify the stability of cloud platform service product functions. Testers can automate the execution of tests, saving labor costs and avoiding the risk of misoperation caused by manual operations.

[0030] Supports testing of cloud platform service products with multiple architectures: Cloud platform service products with different architectures use different images, and currently support the X86 and ARM architectures.

[0031] Supports selective configuration of test scripts: By configuring Job-related parameters, you can configure the test service products to adapt to diverse environmental requirements.

[0032] The API test results of the service product are summarized and output, so that testers can clearly view the pass status of the current test. There is no need to transfer the detailed page results to a server with browser configuration in order to view the results, which avoids tedious operations and makes testing simpler and more convenient. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 It is a schematic flow chart of the method of the present invention. DETAILED DESCRIPTION

[0034] Apache JMeter is a Java-based stress testing tool developed by the Apache organization. It can perform stress and performance tests on HTTP and FTP servers, as well as any database. JMeter can perform regression testing on applications by creating scripts with assertions to verify that the program returns the expected results and generate easy-to-read web test reports.

[0035] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.

[0036] Example 1

[0037] The present invention provides a JMeter-based API test implementation method, comprising:

[0038] Step 1: Write an automated test JMeter script and write an API test script based on the functions of the service product:

[0039] Step 2: Test pre-preparation, upload the API test related files of the automated test JMeter script and API test script to the cloud platform environment, select the node to upload according to the execution environment, check whether the container image exists in the environment, if not, upload the container image to the environment and push it to the image warehouse,

[0040] Step 3: Configure a Job to run the automated test JMeter script and API test script in the cloud platform as a Job: extract the parameters used by the automated test JMeter script and put them into the environment variables of the Job Pod, configure multiple API test scripts, use "spaces" between scripts, and sort the script execution order.

[0041] Step 4: Create a Job by applying apitest.yaml in the environment, call the API test script according to the pre-configuration, and perform automated testing on the environment.

[0042] Step 5: View test results: API test results are stored in the timestamp directory, summarizing the pass rate of the executed scripts. View the number of failed test cases and pass rate of each service product API test to locate and troubleshoot problems.

[0043] The method of the present invention is based on JMeter to write test cases, adapt to multiple architectures, and execute in the cloud platform by starting the test Pod through Job. The execution parameters in the script and the service products to be tested can be configured by configuring the environment variables of the Pod. By summarizing the results of the API test, the test is made simpler and more convenient. The API test is performed using Job containerization, which can quickly and conveniently perform API testing, reduce manual misoperation, and has strong portability. The execution process is simple, and both testers and operation and maintenance personnel can perform it, reducing labor costs.

[0044] Example 2

[0045] Based on Example 1, the method of the present invention may further include writing an automated test JMeter script in step 1:

[0046] According to the thread group, request and listener of the JMeter script, set the loop and number of threads through the thread group, configure the request address, protocol and parameters through the Sampler, and monitor the request and response content through the listener.

[0047] Execute Jmeter components according to the configuration primitives, pre-processors, timers, samplers, post-processors, assertions, and listeners.

[0048] Writing the API test script in step 1 may further include:

[0049] Identify common parameters in service products for subsequent configuration in Jobs.

[0050] Use Chinese identifiers for the test names of the API test script interfaces to facilitate test result output, and extract variable values ​​in the HTTPSampler.path value as parameters to facilitate use on different cloud platforms.

[0051] In step 2, you can further place API test related files in the / home / apitest directory. According to the directory structure, apitest.yaml is the file that defines the JMeter Job, the jmxScript folder stores the API test scripts of the service product, and runjmx.sh is the script file executed when the JMeter container is started.

[0052] The directory structure can be referenced as follows:

[0053]

[0054] In step 3, for environments with the same cloud platform version but different service products, modify the env part in apitest.yaml and replace the environment variables in the runjmx.sh script. If you need to add new parameters, extract the variables in the API test script, add a set of parameters and default values ​​in env according to the example, and replace the parameters in runjmx.sh. The reference code is as follows:

[0055]

[0056] api_test_ip: the domain name of the test cloud platform, which is common to all scripts. api_test_mse_instance_id: the instance_id used in the mse product test. The specific meaning of each parameter should be clarified and well-remarked to facilitate the reading and acquisition of testers and operation and maintenance personnel. Parameters that can be automatically obtained should be obtained by scripts to minimize errors caused by manual acquisition.

[0057] In step 4, the Job is executed on the master node by default. If it is executed on other nodes, modify the nodeSelector to select other nodes. The Job calls the pre-configured API test script to perform automated testing on the environment.

[0058] The detailed results of the corresponding API test results in step 5 are stored in the jmx directory corresponding to the timestamp directory. For example, the timestamp directory is 2000XXXX-XXXXXX-test, and the jmx directory is in the 2000XXXX-XXXXXX-test / jmx directory. The csv file records the interface test results of each service product, the log file records the execution log of JMeter, and the reports directory records the dashboard of each service product test result, which displays the test situation in the form of a chart. Check the index.html file to obtain the specific results of the JMeter script running. The dashboard needs to be viewed on a server with a browser. Each service product has a reports directory, and the command rules are such as cnp-ams.jmx.reports, which can be searched as needed.

[0059] Example 3

[0060] The present invention also provides a JMeter-based API test implementation device, including a script management module, a pre-preparation module, a Job configuration module, a test module and a query display module.

[0061] The script management module writes automated test JMeter scripts and writes API test scripts based on the functions of the service products:

[0062] The pre-preparation module tests the pre-preparation, uploads the API test related files of the automated test JMeter script and the API test script to the cloud platform environment, selects the node to upload according to the execution environment, checks whether the container image exists in the environment, and if not, uploads the container image to the environment and pushes it to the image warehouse.

[0063] The Job configuration module configures the Job, which is used to run the automated test JMeter script and API test script in the cloud platform in the form of a Job: extract the parameters used by the automated test JMeter script and put them into the environment variables of the Job Pod, configure multiple API test scripts, and sort the script execution order.

[0064] The test module creates a Job by applying apitest.yaml in the environment, calls the API test script according to the pre-configuration, and performs automated testing on the environment.

[0065] Query the display module to view test results: API test results are stored in a timestamp directory, summarizing the pass rate of the executed scripts. You can view the number of failed cases and pass rate of each service product API test to locate and troubleshoot problems.

[0066] The information interaction, execution process and other contents between the modules in the above-mentioned device are based on the same concept as the embodiment of the method of the present invention. For the specific contents, please refer to the description in the embodiment of the method of the present invention, and no further description is given here.

[0067] Similarly, the device of the present invention can support conventional functional testing of cloud platform service products: the functions of cloud platform service products can be tested by writing test scripts. When a new version of the service product is released, the test scripts are relatively iteratively maintained to ensure comprehensive coverage of functional use cases. Test cases can be continuously adjusted to adapt to functional changes, and can be executed in different environments to verify the stability of cloud platform service product functions. Testers can automatically perform tests, save labor costs, and avoid the risk of misoperation due to manual operations.

[0068] Supports testing of cloud platform service products with multiple architectures: Cloud platform service products with different architectures use different images, and currently support the X86 and ARM architectures.

[0069] Supports selective configuration of test scripts: By configuring Job-related parameters, you can configure the test service products to adapt to diverse environmental requirements.

[0070] The API test results of the service product are summarized and output, so that testers can clearly view the pass status of the current test. There is no need to transfer the detailed page results to a server with browser configuration in order to view the results, which avoids tedious operations and makes testing simpler and more convenient.

[0071] It should be noted that not all steps and modules in the above-mentioned processes and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.

[0072] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.

Claims

1. A JMeter-based API testing implementation method, characterized by include: Step 1: Write an automated test JMeter script and write an API test script based on the functions of the service product: Step 2: Test pre-preparation, upload the API test related files of the automated test JMeter script and API test script to the cloud platform environment, select the node to upload according to the execution environment, check whether the container image exists in the environment, if not, upload the container image to the environment and push it to the image warehouse, Step 3: Configure a Job to run the automated test JMeter script and API test script in the cloud platform as a Job: extract the parameters used by the automated test JMeter script and put them into the environment variables of the Job Pod, configure multiple API test scripts, and sort the script execution order. Step 4: Create a Job by applying apitest.yaml in the environment, call the API test script according to the pre-configuration, and perform automated testing on the environment. Step 5: View test results: API test results are stored in the timestamp directory, summarizing the pass rate of the executed scripts. View the number of failed test cases and pass rate of each service product API test to locate and troubleshoot problems.

2. According to the JMeter-based API testing implementation method of claim 1, it is characterized by: In step 1, write the automated test JMeter script, including: According to the thread group, request and listener of the JMeter script, set the loop and number of threads through the thread group, configure the request address, protocol and parameters through the Sampler, and monitor the request and response content through the listener. Execute Jmeter components according to the configuration primitives, pre-processors, timers, samplers, post-processors, assertions, and listeners.

3. The JMeter-based API test implementation method according to claim 1 is characterized in that the step of writing an API test script in step 1 comprises: Identify common parameters in service products for subsequent configuration in Jobs. Use Chinese identifiers for the test names of API test script interfaces to facilitate test result output. Extract the variable value in HTTPSampler.path value as a parameter to facilitate use on different cloud platforms.

4. The JMeter-based API testing implementation method according to claim 1 is characterized by: In step 2, place the API test related files in the / home / apitest directory. According to the directory structure, apitest.yaml is the file that defines the JMeterJob, the jmxScript folder stores the API test scripts of the service product, and runjmx.sh is the script file executed when the JMeter container is started.

5. The JMeter-based API testing implementation method according to claim 1 is characterized by: In step 3, for environments with the same cloud platform version but different service products, modify the env part in apitest.yaml and replace the environment variables in the runjmx.sh script. If you need to add new parameters, extract the variables in the API test script, add a set of parameters and default values ​​to env according to the example, and replace the parameters in runjmx.sh.

6. The JMeter-based API testing implementation method according to claim 1 is characterized by: In step 4, the job is executed on the master node by default. If it is executed on other nodes, change it to other nodes, call the pre-configured API test script, and perform automated testing on the environment.

7. The JMeter-based API testing implementation method according to claim 1 is characterized by: The detailed results of the corresponding API test results in step 5 are stored in the jmx directory corresponding to the timestamp directory. The csv file records the interface test results of each service product. The log file records the execution log of JMeter. The reports directory records the dashboard of the test results of each service product, which displays the test status in the form of charts. Check the index.html file to obtain the specific results of the JMeter script running.

8. A JMeter-based API test implementation device, characterized by It includes script management module, pre-preparation module, job configuration module, test module and query display module. The script management module writes automated test JMeter scripts and writes API test scripts based on the functions of the service products: The pre-preparation module tests the pre-preparation, uploads the API test related files of the automated test JMeter script and API test script to the cloud platform environment, selects the node to upload according to the execution environment, checks whether the container image exists in the environment, and if not, uploads the container image to the environment and pushes it to the image warehouse. The Job configuration module configures the Job, which is used to run the automated test JMeter script and API test script in the cloud platform in the form of a Job: extract the parameters used by the automated test JMeter script and put them into the environment variables of the Job Pod, configure multiple API test scripts, and sort the script execution order. The test module creates a Job by applying apitest.yaml in the environment, calls the API test script according to the pre-configuration, and performs automated testing on the environment. Query the display module to view test results: API test results are stored in a timestamp directory, summarizing the pass rate of the executed scripts. You can view the number of failed cases and pass rate of each service product API test to locate and troubleshoot problems.