Interface testing method and system, electronic equipment, storage medium and program product

By building table-based interface test cases and automatically replacing and executing them, the problems of long functional testing time and incomplete scenario coverage in development are solved, and efficient automated testing and more comprehensive test scenario coverage are achieved.

CN119917409APending Publication Date: 2025-05-02CTRIP BUSINESS TRAVEL INFORMATION SERVICE (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411982750.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

During development, functional testing is invested more time and incomplete scenario coverage, resulting in inefficient testing.

Method used

By pre-constructing the interface test cases in the form, each row of table corresponds to an interface test case, including test data, interface request body and expected test results. Replace the identification bit in the interface request body based on the target test data, and re-sell the interface test request, obtain the actual returned result and compare the expected result, and confirm that the test case is passed.

Benefits of technology

Automatic testing is implemented, reducing the time for developers to test functionally, improving the coverage of test scenarios, and simplifying the testing process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917409A_ABST
    Figure CN119917409A_ABST
Patent Text Reader

Abstract

The invention provides an interface testing method and system, electronic equipment, a storage medium and a program product, and the testing method comprises the steps that interface testing cases are constructed in a table mode in advance, each row of tables corresponds to one interface testing case, and each interface testing case comprises testing data, an interface request body and an expected testing result; and in response to the interface test request, reading the table to obtain a corresponding target interface test case, correspondingly replacing a target identification bit in a target interface request body in the target interface test case according to target test data in the target interface test case, and newly initiating the interface test request according to the updated target interface request body, according to the method and the device, writing of the test cases and reading of the corresponding test cases in the table are completed through the table, and automatic testing of corresponding functions can be performed according to the test cases designed in the table.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of software testing, and in particular to an interface testing method, system, electronic device, storage medium and program product. Background Art

[0002] As the business develops, for the increasingly numerous business scenarios, in most cases functional testing is implemented by developers through hard coding. However, this method causes developers to invest more time and the scenario coverage is incomplete. Summary of the invention

[0003] The technical problem to be solved by the present disclosure is to overcome the defects of the prior art that functional testing during development requires a long time investment and incomplete coverage, and to provide an interface testing method, system, electronic device, storage medium and program product.

[0004] The present invention solves the above technical problems through the following technical solutions:

[0005] In a first aspect, a method for testing an interface is provided, the method comprising:

[0006] Constructing several interface test cases in a table format in advance, each row of the table corresponds to one interface test case, and each interface test case includes test data, an interface request body, and an expected test result; wherein the interface request body includes a request body and an identification bit;

[0007] In response to an interface test request, reading the table to obtain a corresponding target interface test case;

[0008] Replace the target identification bit in the target interface request body in the target interface test case according to the target test data in the target interface test case;

[0009] Re-initiate the interface test request according to the updated target interface request body to obtain the actual return result;

[0010] In response to the actual returned result being consistent with the expected test result, it is determined that the interface test case passes.

[0011] Optionally, the interface test case further includes a database execution statement. After the step of responding to the interface test request and reading the table to obtain the corresponding target interface test case, the testing method further includes:

[0012] In response to a target database execution statement included in the target interface test case, replacing the target identification bit in the target database execution statement in the target interface test case with the target test data in the target interface test case;

[0013] Execute the updated target database execution statement.

[0014] Optionally, the interface test case further includes an execution condition, and after the step of responding to the interface test request and reading the table to obtain the corresponding target interface test case, the testing method further includes:

[0015] In response to the target execution conditions in the target interface test cases, an execution order of the target interface test cases is determined.

[0016] Optionally, before the step of responding to the interface test request, the testing method further includes:

[0017] Obtain configuration information, and determine the interface request header through the configuration information;

[0018] An interface test request is executed according to the interface request header and the updated interface request body.

[0019] Optionally, before the step of re-initiating the interface test request according to the updated target interface request body to obtain an actual return result, the testing method further includes:

[0020] The interface request header and the updated interface request body are verified.

[0021] Optionally, the testing method further comprises:

[0022] In response to the interface test being completed, the interface test data generated in the database is cleansed.

[0023] In a second aspect, a test system for an interface is provided, the test system comprising:

[0024] A construction module, used to construct several interface test cases in a table format in advance, each row of the table corresponds to one interface test case, each interface test case includes test data, an interface request body and an expected test result, wherein the interface request body includes a request body and an identification bit;

[0025] An acquisition module, configured to respond to an interface test request and read the table to acquire a corresponding target interface test case;

[0026] A replacement module, which replaces the target identification bit in the target interface request body in the target interface test case according to the target test data in the target interface test case;

[0027] An execution module is configured to re-initiate the interface test request according to the updated target interface request body to obtain an actual return result;

[0028] The comparison module is used to determine that the interface test case has passed in response to the actual returned result being consistent with the expected test result.

[0029] According to a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and used to run on the processor, wherein the processor implements any of the above-mentioned interface testing methods when executing the computer program.

[0030] In a fourth aspect, a computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements any of the above-mentioned interface testing methods.

[0031] In a fifth aspect, a computer program product includes a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned interface testing methods.

[0032] On the basis of being in accordance with the common sense in the art, the above-mentioned preferred conditions can be arbitrarily combined to obtain the preferred embodiments of the present disclosure.

[0033] The positive progressive effect of the present disclosure is that the test cases are written through a table, and after the corresponding function development is completed during the development process, the test cases in the corresponding table are read, and the corresponding functions can be automatically tested according to the test cases designed in the table. In addition, by designing the preceding database data writing and placeholder replacement of input parameters in each test case, different parameter transfers can be executed more conveniently, making the test more convenient, reducing the time for developers to perform functional testing, and improving the coverage of test scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 A flowchart of a method for testing an interface is provided for an exemplary embodiment of the present disclosure;

[0035] Figure 2 A schematic diagram of an interface test case is provided for an exemplary embodiment of the present disclosure;

[0036] Figure 3 A schematic diagram of a database execution statement in an interface test case is provided for an exemplary embodiment of the present disclosure;

[0037] Figure 4 A schematic diagram of providing configuration information for an exemplary embodiment of the present disclosure;

[0038] Figure 5 A module schematic diagram of an interface testing system provided by an exemplary embodiment of the present disclosure;

[0039] Figure 6 The present invention is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION

[0040] The present disclosure is further described below by way of examples, but the present disclosure is not limited to the scope of the examples.

[0041] Prefixes such as "first" and "second" are used in the embodiments of the present disclosure only to distinguish different description objects, and have no limiting effect on the position, order, priority, quantity or content of the described objects. The use of prefixes such as ordinal numbers to distinguish description objects in the embodiments of the present disclosure does not constitute a limitation on the described objects. For the statement of the described objects, please refer to the description in the context of the claims or embodiments, and no unnecessary limitation should be constituted due to the use of such prefixes. In addition, in the description of the present embodiment, unless otherwise specified, the meaning of "plurality" is two or more.

[0042] Figure 1 A flowchart of a method for testing an interface is provided for an exemplary embodiment of the present disclosure. The method for testing an interface includes:

[0043] Step 101, construct several interface test cases in a table format in advance, each row of the table corresponds to an interface test case, and each interface test case includes test data, an interface request body and expected test results; wherein the interface request body includes a request body and an identification bit.

[0044] Specifically, when sending an interface request, the interface request is initiated to the server by combining the request header and the request body, and then the server returns the corresponding interface return result. In this embodiment, the test case can be constructed in Excel, and each row corresponds to an interface test case, which includes test data, interface request body and expected test results.

[0045] Step 102: In response to the interface test request, read the table to obtain the corresponding target interface test case.

[0046] Specifically, in this embodiment, the jdbc+framemaker+easyexcel+aop technology stack is used to read the interface test cases in the corresponding table. In response to the interface test request, the corresponding interface test case will be found according to the corresponding ID.

[0047] Step 103: Replace the target identification bit in the target interface request body in the target interface test case according to the target test data in the target interface test case.

[0048] Specifically, Figure 2As shown, in the interface request body part of the interface test case, the dynamic parameter part is marked with a placeholder (${}). There are corresponding placeholders for different dynamic parameters. In response to the interface test request, after finding the corresponding interface test case, the test data in the test case will be used to replace the placeholder in the interface request body, so that the updated interface request body is the interface request body during the actual interface test.

[0049] Step 104: Re-initiate the interface test request according to the updated target interface request body to obtain the actual return result.

[0050] Specifically, the updated interface request body is combined with the request header to obtain the interface request in the interface test case, which is then sent to the backend server to obtain the return result of the actual interface.

[0051] Step 105: In response to the actual returned result being consistent with the expected test result, it is determined that the interface test case has passed.

[0052] Specifically, compare the actual interface request result returned by the backend with the expected test result in the test case. If the returned results are consistent, the interface test case passes. If they are inconsistent, the interface test fails and error troubleshooting is required.

[0053] In this embodiment, the test case is written through a table, and after the corresponding function development is completed during the development process, the test case in the corresponding table is read, and the corresponding function can be automatically tested according to the test case designed in the table. By designing placeholders in each test case to replace the input parameters, different parameter transfers can be executed more conveniently, making testing more convenient, reducing the time for developers to perform functional testing, and improving the coverage of test scenarios.

[0054] In one embodiment, the interface test case also includes a database execution statement. After the step of reading a table to obtain a corresponding target interface test case in response to an interface test request, the test method further includes responding to a target database execution statement included in the target interface test case, replacing a target identification bit in the target database execution statement in the target interface test case with target test data in the target interface test case, and executing the updated target database execution statement.

[0055] Specifically, Figure 3As shown, the interface test case can include database execution statements, and can support multiple data sources (MySQL, SqlServer, Redis, SOA) at the same time. Since the interface may rely on pre-prepared data when the interface test is requested, it is possible to configure whether to execute the database operation first before executing the test case as the preparation data for the interface test. When the interface test case contains a database execution statement, the database execution statement is executed first as the preparation data for the subsequent interface test. The database execution statement also contains placeholders, so when executing the database statement, the test data in the test case will be replaced with the placeholders in the database execution statement, and then the database execution statement will be executed according to the replacement update.

[0056] In this embodiment, by designing the preceding database data writing and replacing the input parameters with placeholders in each test case, it is possible to more conveniently execute different parameter transfers, automatically prepare test data, and make testing more convenient.

[0057] In one embodiment, the interface test case also includes an execution condition. After responding to the interface test request and reading the table to obtain the corresponding target interface test case, the testing method also includes: determining the execution order of the target interface test case in response to the target execution condition in the target interface test case.

[0058] Specifically, there are interdependencies between test cases. When executing interface A, it may be necessary to execute interface B first and rely on the return data of interface B. Therefore, when designing interface test cases, there is a dependency field in the table to judge the execution conditions and thus determine the order of interface execution. For example, when executing interface A test case, it is detected that interface B test case needs to be executed first. The test method will execute interface B test case first, and then execute interface A test case after execution is completed.

[0059] In this embodiment, the execution order can be automatically determined through the execution conditions, so that the corresponding interface test can be completed at one time without repeatedly executing other interfaces.

[0060] In one embodiment, before the step of responding to the interface test request, the testing method further includes:

[0061] Obtain configuration information and determine the interface request header through the configuration information;

[0062] Execute the interface test request according to the interface request header and the updated interface request body.

[0063] Specifically, when sending an interface test request, the interface request header and the interface request body need to be assembled before sending the interface request to the backend. The interface request header can read the corresponding configuration information and thus be automatically generated. Figure 4As shown, the environment parameters and channel parameters of this test can be determined in the code. The specific parameters of the server can be determined by the above configuration information, thereby determining the request header. After obtaining the updated interface request body and the determined request header, the interface test request is sent to the target backend.

[0064] In this embodiment, by acquiring configuration parameters and determining the request header, multiple test environments can be dynamically switched, thereby achieving interface automation testing in multiple different test environments.

[0065] In one embodiment, before the step of re-initiating the interface test request according to the updated target interface request body to obtain the actual return result, the testing method further includes verifying the interface request header and the updated interface request body.

[0066] Specifically, before sending the interface test request, the interface request header and request body will be further checked to prevent the interface test request itself from being assembled incorrectly or replaced incorrectly, thereby causing subsequent interface requests to fail.

[0067] In one embodiment, the testing method further includes cleaning the interface test data in response to the interface test being completed.

[0068] Specifically, through AOP (Aspect Oriented Programming), data is inserted before executing the use case, and the test data generated in the database during the test is deleted after execution, preventing the next test from introducing previous test data and ensuring that no data pollution occurs.

[0069] In one embodiment, the testing method further includes counting the success rate of the test cases, and determining whether to allow the new code to be merged into the main branch according to the interface test case coverage in the development process. Thus, multiple scenario test cases are maintained, which can be convenient for statistical viewing, and the code coverage can be calculated to control whether the new code can be merged, thereby ensuring the stability of the merged code.

[0070] Corresponding to the aforementioned test method embodiment, the present disclosure also provides an embodiment of a test system.

[0071] Figure 5 A module schematic diagram of an interface testing system provided by an exemplary embodiment of the present disclosure, the system comprising:

[0072] Construction module 1 is used to construct several interface test cases in a table format in advance, each row of the table corresponds to an interface test case, and each interface test case includes test data, an interface request body and expected test results, wherein the interface request body includes a request body and an identification bit.

[0073] The acquisition module 2 is used to respond to the interface test request and read the table to obtain the corresponding target interface test case.

[0074] The replacement module 3 replaces the target identification bit in the target interface request body in the target interface test case according to the target test data in the target interface test case.

[0075] Execution module 4 re-initiates the interface test request according to the updated target interface request body to obtain the actual return result.

[0076] The comparison module 5 is used to determine that the interface test case has passed in response to the actual returned result being consistent with the expected test result.

[0077] In one embodiment, the replacement module is further used to replace the target identification bit in the target database execution statement in the target interface test case with the target test data in the target interface test case in response to the target database execution statement included in the target interface test case.

[0078] The execution module is also used to execute the updated database execution statement.

[0079] In one embodiment, the execution module is further used to determine the execution order of the target interface test cases in response to the execution conditions in the target interface test cases.

[0080] In one embodiment, the acquisition module is further used to acquire configuration information and determine the interface request header through the configuration information;

[0081] The execution module is also used to execute the interface test request according to the interface request header and the updated interface request body.

[0082] In one embodiment, the test system further includes a verification module, and the verification module is used to verify the interface request header and the updated interface request body.

[0083] In one embodiment, the test system further includes a cleaning module, and the cleaning module is used to clean the interface test data generated in the database in response to the completion of the interface test.

[0084] As for the system embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The system embodiment described above is only illustrative, wherein the units described as separate components may or may not be physically separated, and the components as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the disclosed solution.

[0085] Figure 6This is a structural diagram of an electronic device shown in an example embodiment of the present disclosure, the electronic device includes a memory, a processor, and a computer program stored in the memory and used to run on the processor, and the processor implements the test method described in any of the above embodiments when executing the computer program. Figure 6 The electronic device 60 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0086] like Figure 6 As shown, the electronic device 60 may be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 60 may include, but are not limited to: at least one processor 61, at least one memory 62, and a bus 63 connecting different system components (including the memory 62 and the processor 61).

[0087] The bus 63 includes a data bus, an address bus, and a control bus.

[0088] The memory 62 may include a volatile memory, such as a random access memory (RAM) 621 and / or a cache memory 622 , and may further include a read-only memory (ROM) 623 .

[0089] The memory 62 may also include a program tool 625 (or utility) having a set (at least one) of program modules 624, such program modules 624 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0090] The processor 61 executes various functional applications and data processing by running the computer program stored in the memory 62, such as the test method provided in any of the above embodiments.

[0091] The electronic device 60 may also communicate with one or more external devices 64 (e.g., keyboards, pointing devices, etc.). Such communication may be performed via an input / output (I / O) interface 65. Furthermore, the electronic device 60 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 66. As shown, the network adapter 66 communicates with other modules of the electronic device 60 via a bus 63. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 60, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.

[0092] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.

[0093] The embodiment of the present disclosure further provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the test method provided by any of the above embodiments is implemented.

[0094] The readable storage medium may include but is not limited to: a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device or any suitable combination of the above.

[0095] The embodiment of the present disclosure further provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned testing methods.

[0096] Among them, the program code for executing the computer program product of the present disclosure can be written in any combination of one or more programming languages, and the program code can be executed completely on the user device, partially on the user device, as an independent software package, partially on the user device and partially on a remote device, or completely on the remote device.

[0097] Although the specific embodiments of the present disclosure are described above, those skilled in the art should understand that this is only an example, and the protection scope of the present disclosure is defined by the appended claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present disclosure, but these changes and modifications all fall within the protection scope of the present disclosure.

Claims

1. A method for testing an interface, characterized in that: The test method includes: Constructing several interface test cases in a table format in advance, each row of the table corresponds to one interface test case, and each interface test case includes test data, an interface request body, and an expected test result; wherein the interface request body includes a request body and an identification bit; In response to an interface test request, reading the table to obtain a corresponding target interface test case; Replace the target identification bit in the target interface request body in the target interface test case according to the target test data in the target interface test case; Re-initiate the interface test request according to the updated target interface request body to obtain the actual return result; In response to the actual returned result being consistent with the expected test result, it is determined that the interface test case passes.

2. The testing method according to claim 1, characterized in that: The interface test case also includes a database execution statement. After the step of responding to the interface test request and reading the table to obtain the corresponding target interface test case, the test method further includes: In response to a target database execution statement included in the target interface test case, replacing the target identification bit in the target database execution statement in the target interface test case with the target test data in the target interface test case; Execute the updated target database execution statement.

3. The testing method according to claim 1, characterized in that: The interface test case also includes an execution condition. After the step of responding to the interface test request and reading the table to obtain the corresponding target interface test case, the test method further includes: In response to the target execution conditions in the target interface test cases, an execution order of the target interface test cases is determined.

4. The testing method according to claim 1, characterized in that: Before the step of responding to the interface test request, the test method further includes: Obtain configuration information, and determine the interface request header through the configuration information; An interface test request is executed according to the interface request header and the updated interface request body.

5. The testing method according to claim 4, characterized in that: Before the step of re-initiating the interface test request according to the updated target interface request body to obtain an actual return result, the test method further includes: The interface request header and the updated interface request body are verified.

6. The testing method according to any one of claims 1 to 5, characterized in that: The test method also includes: In response to the interface test being completed, the interface test data generated in the database is cleansed.

7. An interface testing system, characterized in that: The test system comprises: A construction module is used to construct several interface test cases in a table format in advance, each row of the table corresponds to one interface test case, and each interface test case includes test data, an interface request body and an expected test result; wherein the interface request body includes a request body and an identification bit; An acquisition module, configured to respond to an interface test request and read the table to acquire a corresponding target interface test case; A replacement module, which replaces the target identification bit in the target interface request body in the target interface test case according to the target test data in the target interface test case; An execution module is configured to re-initiate the interface test request according to the updated target interface request body to obtain an actual return result; The comparison module is used to determine that the interface test case has passed in response to the actual returned result being consistent with the expected test result.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and used to run on the processor, characterized in that: When the processor executes the computer program, the interface testing method according to any one of claims 1 to 6 is implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the interface testing method according to any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the interface testing method according to any one of claims 1 to 6 is implemented.