Python-based automatic interface testing method

By separating the directories and files of interface automation testing in the Python environment, the efficiency of interface automation testing is improved and the code is simplified. It solves the problems of single data structure and complex logic in existing tools, simplifies the testing process and saves time.

CN118760601APending Publication Date: 2024-10-11INSPUR QILU SOFTWARE IND
View PDF 0 Cites 2 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing interface automation testing tools have problems such as single data structure, poor scalability, large amount of code, and unsuccinct logic. Especially in the Python environment, ordinary interface automation frameworks need to separately encapsulate the read and write excel methods, and in The interface parameters need to be assembled in the script, which increases the complexity of the code and the difficulty of data maintenance.

Method used

By creating new service directory, data directory, config directory and case directory in Python, they are used to store interface API, test data, environment information and use case writing respectively. Use the run.py file to assemble the test suite and generate reports to realize automated interface testing. Specifically, it includes obtaining resource information, performing migration operations, and verifying the correctness of resource status and volume.

Benefits of technology

It improves the efficiency of automated interface testing, simplifies code logic, avoids repeated manual testing, saves a lot of time, and achieves a more flexible testing framework by separating data and use cases, APIs and logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760601A_ABST
    Figure CN118760601A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic interface testing method based on Python, and relates to the technical field of automatic testing. The method comprises the following steps: creating a service directory, creating a service.py file of a corresponding module, storing an interface api for packaging, creating a data directory, creating a data.py file, storing test data required by each case, creating a config directory, creating a config.py file, storing an environment address, login information, a resource pool and application information, creating a case directory, compiling a case testcas.py file, importing a required database, calling a corresponding interface api, and storing the test data required by each case. The method comprises the following steps of: inputting parameters, realizing each case, creating a run.py file, assembling a test suite and appointing a report storage path and a report name, running the test suite and generating a report, executing the run.py file, running the test case, generating a report and storing the report in a report directory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention discloses a method, and relates to the technical field of automated testing, in particular to an interface automated testing method based on Python. Background Art

[0002] Interface testing is a test of the interface between system components. It is mainly used to test the interface between the system and other external systems, as well as the interface between various sub-modules within the system. The focus of the test is to check the correctness of interface parameter transmission, the correctness of interface function implementation, the correctness of output results, and the integrity and rationality of fault-tolerant processing of various abnormal situations.

[0003] Interface testing can currently be achieved through tools such as soupui, postman, jmeter, and UnitTest. However, when using tools to automate interfaces, the test data structure is single, the scalability is poor, and it is not flexible. In addition, the common Python interface automation framework not only needs to encapsulate the methods of reading and writing Excel separately, but also needs to assemble the read interface parameters into Json format again in the script, which not only increases the amount of code, but also makes data maintenance more troublesome, and the logic of the entire framework is not concise enough. Summary of the invention

[0004] In view of the problems in the prior art, the present invention provides a Python-based interface automation testing method, which has the characteristics of strong versatility, simple implementation, etc. and has broad application prospects.

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

[0006] The present invention provides a Python-based interface automation testing method, comprising:

[0007] Create a new service directory and a new service.py file for the corresponding module to store the encapsulated interface API.

[0008] Create a new data directory and a new data.py file to store the test data required for each use case.

[0009] Create a new config directory and a new config.py file to store environment addresses, login information, resource pools, and application information.

[0010] Create a new case directory, write the test case test_case.py file, import the required database, call the corresponding interface api, pass in parameters, and implement each use case.

[0011] Create a new run.py file, assemble the test suite and specify the report storage path and report name, run the test suite and generate a report, execute the run.py file, run the test case, generate a report and store it in the report directory.

[0012] Furthermore, the running test cases in the described Python-based interface automation testing method include: verifying the test cases, wherein during the verification of the test cases, the resource information that needs to be migrated by the application is obtained, resource migration is performed according to the test data in the data.py file, and whether the application status is correct after the application resources are migrated through the interface API, and then whether the resource amount of the application resource migration is correct is verified. If all verifications pass, the test case of the interface API passes the verification, otherwise the verification fails.

[0013] Furthermore, the verification test case process in the interface automation testing method based on Python specifically includes:

[0014] Get the application's migration resource information: Get the node name and computing power of the source architecture of the one-cloud-multi-core application, as well as the node name and computing power of the target architecture through the API.

[0015] Query and record the name and quantity of the source architecture container group before migration, and calculate the computing power based on the node information and container group configuration, as well as the name and quantity of the target architecture container group and calculate the computing power based on the node information and container group configuration;

[0016] Perform cross-architecture migration based on the test data in the data.py file to migrate the container group from the source architecture to the target architecture;

[0017] First verify whether the one-cloud-multi-core application status is correct after migrating the number of containers and computing resources through the API interface;

[0018] Verify whether the amount of application resource migration is correct: query and record the name and number of the source architecture container group after migration, and calculate the computing power according to the node information and container group configuration, as well as the name and number of the target architecture container group and calculate the computing power according to the node information and container group configuration.

[0019] Verify that the reduction in the number of source architecture container groups after migration is equal to the preset target number.

[0020] Verify whether the reduced computing power of the source architecture container group after migration is consistent with the increased computing power of the target architecture container group;

[0021] If all verifications pass, the test case passes the verification, otherwise the verification fails.

[0022] Furthermore, the method of verifying whether the computing power reduced by the source architecture container group after migration is consistent with the computing power increased by the target architecture container group in the Python-based interface automation testing method includes:

[0023] Based on the query results after migration, calculate the reduced computing power of the source architecture container group.

[0024] According to the query results after migration, calculate the increased computing power of the target architecture container group, and determine whether the increased computing power of the target architecture container group is greater than or equal to the reduced computing power of the source architecture container group.

[0025] The present invention also provides an interface automation testing device based on Python, comprising a file management module and a test execution module.

[0026] The file management module creates a new service directory and a new service.py file for the corresponding module to store the encapsulated interface API.

[0027] Create a new data directory and a new data.py file to store the test data required for each use case.

[0028] Create a new config directory and a new config.py file to store environment addresses, login information, resource pools, and application information.

[0029] Create a new case directory, write the test case test_case.py file, import the required database, call the corresponding interface api, pass in parameters, and implement each use case.

[0030] Create a new run.py file to assemble the test suite and specify the report storage path and report name, run the test suite and generate a report.

[0031] The test execution module executes the run.py file, runs the test cases, generates reports and stores them in the report directory.

[0032] Furthermore, the test execution module of the Python-based interface automation testing device runs test cases, including: verifying test cases, wherein during the verification of test cases, resource information that needs to be migrated by the application is obtained, resource migration is performed according to the test data in the data.py file, and whether the application status is correct after the application resources are migrated through the interface API, and then whether the resource amount of the application resource migration is correct is verified. If all verifications pass, the test case of the interface API passes the verification, otherwise the verification fails.

[0033] Furthermore, the test execution module verification test case process of the interface automation test device based on Python specifically includes:

[0034] Get the application's migration resource information: Get the node name and computing power of the source architecture of the one-cloud-multi-core application, as well as the node name and computing power of the target architecture through the API.

[0035] Query and record the name and quantity of the source architecture container group before migration, and calculate the computing power based on the node information and container group configuration, as well as the name and quantity of the target architecture container group and calculate the computing power based on the node information and container group configuration;

[0036] Perform cross-architecture migration based on the test data in the data.py file to migrate the container group from the source architecture to the target architecture;

[0037] First verify whether the one-cloud-multi-core application status is correct after migrating the number of containers and computing resources through the API interface;

[0038] Verify whether the amount of application resource migration is correct: query and record the name and number of the source architecture container group after migration, and calculate the computing power according to the node information and container group configuration, as well as the name and number of the target architecture container group and calculate the computing power according to the node information and container group configuration.

[0039] Verify that the reduction in the number of source architecture container groups after migration is equal to the preset target number.

[0040] Verify whether the reduced computing power of the source architecture container group after migration is consistent with the increased computing power of the target architecture container group;

[0041] If all verifications pass, the test case passes the verification, otherwise the verification fails.

[0042] Furthermore, the test execution module of the Python-based interface automation test device verifies whether the computing power reduced by the source architecture container group after the migration is consistent with the computing power increased by the target architecture container group, including:

[0043] Based on the query results after migration, calculate the reduced computing power of the source architecture container group.

[0044] According to the query results after migration, calculate the increased computing power of the target architecture container group, and determine whether the increased computing power of the target architecture container group is greater than or equal to the reduced computing power of the source architecture container group.

[0045] The benefits of the present invention are:

[0046] The data is separated from the use case by storing the interface data in the py file, the interface is separated from the use case by storing the encapsulated api in the py file, a new case file is created and a test case is written, the test case is run using the execution function, and a test report is generated after the execution is completed. The present invention can greatly improve the execution efficiency of the smoke test case, avoid major problems that affect the test work of the tester, and avoid repeated manual smoke testing of each version, saving a lot of time. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0048] Figure 2 It is a flowchart of a verification test case of the present invention. DETAILED DESCRIPTION

[0049] 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.

[0050] Example 1

[0051] The present invention provides a Python-based interface automation testing method, comprising:

[0052] Step 1: Create a new service directory and a service.py file of the corresponding module to store the encapsulated interface API. The py files of each interface can be saved to encapsulate the API in the service library, such as defining a class that defines the interface function for sending request requests. You can also create a new common folder to save the py files of the public methods encapsulated based on the interface function in the service, import the interface file, create a new class, call the interface function and pass parameters, obtain the return value, and judge the interface return status.

[0053] Step 2: Create a new data directory and a new data.py file to store the test data required for each use case.

[0054] Step 3: Create a new config directory and a new config.py file to store the environment address, login information, resource pool, and application information.

[0055] Step 4: Create a new case directory, write a test case test_case.py file, import the required database, call the corresponding interface api, pass in parameters, and implement each test case. The case directory is used to save the py file of the test case. In the test case py file, import the required packages, data files, service files, common files, create a new class, call the interface public method and pass in parameters, obtain the return value, assert status and other information.

[0056] Step 5: Create a new run.py file, assemble the test suite and specify the report storage path and report name, run the test suite and generate a report, execute the run.py file, run the test case, generate a report and store it in the report directory.

[0057] The running of the test case may further include: verifying the test case, during which the resource information that needs to be migrated by the application is obtained, resource migration is performed according to the test data in the data.py file, and it is verified whether the application status is correct after the application resources are migrated through the interface api, and then whether the resource amount of the application resource migration is correct. If all verifications pass, the test case of the interface api passes the verification, otherwise the verification fails.

[0058] Example 2

[0059] One cloud, multiple cores application is an important module of the cloud platform project. It enables a cloud platform to manage computing resources of different chip architectures, as well as unified management and scheduling of heterogeneous resources. The cloud platform shields the differences in underlying architectures and provides users with a consistent experience of cloud computing services.

[0060] Based on Example 1, the verification test case process in the method of the present invention may further specifically include:

[0061] Get the application's migration resource information: Get the node name and computing power of the source architecture of the one-cloud-multi-core application, as well as the node name and computing power of the target architecture through the API.

[0062] Query and record the name and number of the source architecture container group before migration, and calculate the computing power based on the node information and container group configuration, as well as the name and number of the target architecture container group and calculate the computing power based on the node information and container group configuration.

[0063] Perform cross-schema migration based on the test data in the data.py file to migrate the container group from the source schema to the target schema.

[0064] First verify whether the one-cloud-multi-core application status is correct after migrating the number of containers and computing resources through the interface API.

[0065] Verify whether the amount of application resource migration is correct: query and record the name and number of the source architecture container group after migration, and calculate the computing power according to the node information and container group configuration, as well as the name and number of the target architecture container group and calculate the computing power according to the node information and container group configuration.

[0066] Verify that the reduction in the number of source architecture container groups after migration is equal to the preset target number.

[0067] Verifying whether the reduced computing power of the source architecture container group after migration is consistent with the increased computing power of the target architecture container group may further include:

[0068] Based on the query results after migration, calculate the reduced computing power of the source architecture container group.

[0069] According to the query results after migration, calculate the increased computing power of the target architecture container group, and determine whether the increased computing power of the target architecture container group is greater than or equal to the reduced computing power of the source architecture container group.

[0070] If all verifications pass, the test case passes the verification, otherwise the verification fails.

[0071] Example 3

[0072] The present invention also provides an interface automation testing device based on Python, comprising a file management module and a test execution module.

[0073] The file management module creates a new service directory and a new service.py file for the corresponding module to store the encapsulated interface API.

[0074] Create a new data directory and a new data.py file to store the test data required for each use case.

[0075] Create a new config directory and a new config.py file to store environment addresses, login information, resource pools, and application information.

[0076] Create a new case directory, write the test case test_case.py file, import the required database, call the corresponding interface api, pass in parameters, and implement each use case.

[0077] Create a new run.py file to assemble the test suite and specify the report storage path and report name, run the test suite and generate a report.

[0078] The test execution module executes the run.py file, runs the test cases, generates reports and stores them in the report directory.

[0079] As 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, the specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.

[0080] Similarly, the device of the present invention stores interface data through py files to separate data from use cases, stores encapsulated APIs through py files to separate interfaces from use cases, creates new case files and writes test cases, uses execution functions to run test cases, and generates test reports after execution. The present invention can greatly improve the execution efficiency of smoke test cases, avoid major problems that affect the test work of testers, and avoid repeated manual smoke tests for each version, saving a lot of time.

[0081] 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.

[0082] 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 Python-based interface automation testing method, Its characteristics are include: Create a new service directory and a new service.py file for the corresponding module to store the encapsulated interface API. Create a new data directory and a new data.py file to store the test data required for each use case. Create a new config directory and a new config.py file to store environment addresses, login information, resource pools, and application information. Create a new case directory, write the test case test_case.py file, import the required database, call the corresponding interface api, pass in parameters, and implement each use case. Create a new run.py file, assemble the test suite and specify the report storage path and report name, run the test suite and generate a report, execute the run.py file, run the test case, generate a report and store it in the report directory.

2. According to the Python-based interface automation testing method of claim 1, Its characteristics are The running test case includes: verifying the test case, during which the resource information that needs to be migrated by the application is obtained, resource migration is performed according to the test data in the data.py file, and it is verified whether the application status is correct after the application resources are migrated through the interface api, and then whether the resource amount of the application resource migration is correct. If all verifications pass, the test case of the interface api passes the verification, otherwise the verification fails.

3. According to the Python-based interface automation testing method of claim 2, Its characteristics are The verification test case process specifically includes: Get the application's migration resource information: Get the node name and computing power of the source architecture of the one-cloud-multi-core application, as well as the node name and computing power of the target architecture through the API. Query and record the name and quantity of the source architecture container group before migration, and calculate the computing power based on the node information and container group configuration, as well as the name and quantity of the target architecture container group and calculate the computing power based on the node information and container group configuration; Perform cross-architecture migration based on the test data in the data.py file to migrate the container group from the source architecture to the target architecture; First verify whether the one-cloud-multi-core application status is correct after migrating the number of containers and computing resources through the API interface; Verify whether the amount of application resource migration is correct: query and record the name and number of the source architecture container group after migration, and calculate the computing power according to the node information and container group configuration, as well as the name and number of the target architecture container group and calculate the computing power according to the node information and container group configuration. Verify that the reduction in the number of source architecture container groups after migration is equal to the preset target number. Verify whether the reduced computing power of the source architecture container group after migration is consistent with the increased computing power of the target architecture container group; If all verifications pass, the test case passes the verification, otherwise the verification fails.

4. According to the Python-based interface automation testing method of claim 3, Its characteristics are The verification of whether the reduced computing power of the source architecture container group after the migration is consistent with the increased computing power of the target architecture container group includes: Based on the query results after migration, calculate the reduced computing power of the source architecture container group. According to the query results after migration, calculate the increased computing power of the target architecture container group, and determine whether the increased computing power of the target architecture container group is greater than or equal to the reduced computing power of the source architecture container group.

5. An interface automation testing device based on Python, Its characteristics are Including file management module and test execution module, The file management module creates a new service directory and a new service.py file for the corresponding module to store the encapsulated interface API. Create a new data directory and a new data.py file to store the test data required for each use case. Create a new config directory and a new config.py file to store environment addresses, login information, resource pools, and application information. Create a new case directory, write the test case test_case.py file, import the required database, call the corresponding interface api, pass in parameters, and implement each use case. Create a new run.py file to assemble the test suite and specify the report storage path and report name, run the test suite and generate a report. The test execution module executes the run.py file, runs the test cases, generates reports and stores them in the report directory.

6. The interface automation testing device based on Python according to claim 5, Its characteristics are The test execution module runs test cases, including: verifying test cases, during which the resource information that needs to be migrated by the application is obtained, resource migration is performed according to the test data in the data.py file, and whether the application status is correct after the application resources are migrated through the interface API, and then verifying whether the resource amount of the application resource migration is correct. If all verifications pass, the test case of the interface API passes the verification, otherwise the verification fails.

7. The interface automation testing device based on Python according to claim 6, Its characteristics are The test execution module verifies the test case process, including: Get the application's migration resource information: Get the node name and computing power of the source architecture of the one-cloud-multi-core application, as well as the node name and computing power of the target architecture through the API. Query and record the name and quantity of the source architecture container group before migration, and calculate the computing power based on the node information and container group configuration, as well as the name and quantity of the target architecture container group and calculate the computing power based on the node information and container group configuration; Perform cross-architecture migration based on the test data in the data.py file to migrate the container group from the source architecture to the target architecture; First verify whether the one-cloud-multi-core application status is correct after migrating the number of containers and computing resources through the API interface; Verify whether the amount of application resource migration is correct: query and record the name and number of the source architecture container group after migration, and calculate the computing power according to the node information and container group configuration, as well as the name and number of the target architecture container group and calculate the computing power according to the node information and container group configuration. Verify that the reduction in the number of source architecture container groups after migration is equal to the preset target number. Verify whether the reduced computing power of the source architecture container group after migration is consistent with the increased computing power of the target architecture container group; If all verifications pass, the test case passes the verification, otherwise the verification fails.

8. The Python-based interface automation testing device according to claim 7, Its characteristics are The test execution module verifies whether the reduced computing power of the source architecture container group after migration is consistent with the increased computing power of the target architecture container group, including: Based on the query results after migration, calculate the reduced computing power of the source architecture container group. According to the query results after migration, calculate the increased computing power of the target architecture container group, and determine whether the increased computing power of the target architecture container group is greater than or equal to the reduced computing power of the source architecture container group.

Citation Information

Cited By

  • Method and device for automatically generating interface automation test project architecture and medium

    CN119621585A

  • Method, device and medium for automatically generating interface automation test project architecture

    CN119621585B