Interface test case processing method, computer equipment and computer program product
By obtaining the target code snippet to update the interface documents and use case collection, the problem that existing interface testing methods cannot be updated in time when the interface code changes, and the accuracy and timeliness of test cases are improved.
Patent Information
- Application Number
- CN202411964011.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-18
AI Technical Summary
Existing interface testing methods cannot perceive these changes in time when interface code changes, resulting in lag in the update processing of interface documents and use case collections, which reduces the accuracy and coverage of test cases.
Ensure consistency between interface code, interface documentation, and test cases by obtaining the target code snippet associated with the specified interface, and updating the interface document and use case collection.
Improve the accuracy and timeliness of test cases, ensure that the test cases can accurately reflect the actual functions and behavior of the current interface, and avoid errors caused by the inconsistent interface documents with the actual implementation.
Smart Images

Figure CN119847930A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the server field, and in particular, relates to an interface test case processing method, a computer device, and a computer program product. Background Art
[0002] In the process of software development, interface testing is a very important task. Interface testing is a test of the interface between system components, 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.
[0003] When the interface code changes, the existing interface testing methods are often unable to perceive these changes in time, resulting in a lag in the update of interface documents and use case sets. This makes the test cases unable to accurately reflect the actual functions and behaviors of the current interface, thereby reducing the accuracy of the test cases and may lead to insufficient test coverage or erroneous test results. Summary of the invention
[0004] The embodiments of the present application provide an interface test case processing method, a computer device, and a computer program product, which can ensure the consistency among the interface code, interface document, and interface use case of the same interface, and improve the accuracy and timeliness of the test case.
[0005] A first aspect of an embodiment of the present application provides an interface test case processing method, comprising:
[0006] Acquire a target code segment associated with a specified interface, wherein the target code segment represents a difference between a current interface code of the specified interface and a target interface code obtained after code change;
[0007] Based on the target code snippet, updating the current interface document of the specified interface to obtain a target interface document;
[0008] Based on the target interface document, use case update processing is performed on the existing use case set of the designated interface to obtain a target use case set.
[0009] In an implementation of the first aspect, the step of performing document update processing on the current interface document of the specified interface based on the target code fragment to obtain the target interface document includes:
[0010] Based on the interface name of the specified interface, locate the position of the specified interface in the current interface document;
[0011] Based on the target code fragment, the document content at the position is updated to obtain the target interface document.
[0012] In an implementation of the first aspect, performing use case update processing on an existing use case set of the specified interface based on the target interface document to obtain a target use case set includes:
[0013] Reading target content adapted to the target code fragment in the target interface document;
[0014] Performing change identification on the target content to obtain at least one change point, wherein the change point is used to describe the changed content in the current interface document in a preset format;
[0015] Generating target test cases for each of the change points based on the change points;
[0016] Based on each of the target test cases, the existing test case set of the specified interface is updated to obtain a target test case set.
[0017] In an implementation of the first aspect, generating a target test case for each of the change points based on the change points includes:
[0018] Determine the designated use case template for each of the change points based on a preset use case template library;
[0019] Based on each of the change points and the designated test case template of each of the change points, a target test case for each of the change points is generated.
[0020] In an implementation of the first aspect, determining the designated use case template for each of the change points based on a preset use case template library includes:
[0021] In the preset use case template library, respectively match the use case template of each change point;
[0022] For any of the change points, if there is no existing use case template matching the change point, a new use case template for the change point is created as a designated use case template for the change point;
[0023] For any of the change points, if there is an existing use case template that matches the change point, the existing use case template is used as the designated use case template for the change point.
[0024] In an implementation of the first aspect, the method further includes:
[0025] If any of the specified use case templates is a new use case template, storing the specified use case template in the use case template library;
[0026] For any of the change points, if there is an existing test case for the change point, the existing test case is determined as a target test case for the change point.
[0027] In an implementation of the first aspect, the step of identifying a change in the target content to obtain at least one change point includes:
[0028] Based on the preset identification elements, the target content is identified for changes, and the associated content for each identification element is determined;
[0029] At least one change point of the designated interface is determined based on the associated content of each of the identification elements.
[0030] In an implementation of the first aspect, obtaining a target code segment associated with a specified interface includes:
[0031] Obtain a change identifier, where the change identifier is used to indicate an interface whose interface code has changed;
[0032] Based on the interface name of the designated interface, determining a target change identifier of the designated interface from each of the change identifiers;
[0033] Based on the target change identifier, a target code segment associated with the designated interface is determined.
[0034] In an implementation of the first aspect, after performing use case update processing on the existing use case set of the specified interface based on the target interface document to obtain the target use case set, the method further includes:
[0035] Performing consistency verification processing on the target interface code of the designated interface, the target interface document, and the target use case set to obtain a verification result, wherein the target interface code includes the target code fragment;
[0036] If the consistency check process passes, then based on the target use case set, an interface test is performed on the designated interface to obtain a test result.
[0037] In an implementation of the first aspect, performing an interface test on the designated interface based on the target use case set to obtain a test result includes:
[0038] Generate a test script corresponding to the target use case set;
[0039] Run the test script, perform the interface test on the specified interface, and obtain the test result.
[0040] A second aspect of an embodiment of the present application provides an interface test case processing device, comprising:
[0041] An acquisition module, used for acquiring a target code segment associated with a specified interface, wherein the target code segment represents a difference between a current interface code of the specified interface and a target interface code obtained after code change;
[0042] A document updating module, used to perform document updating processing on the current interface document of the specified interface based on the target code fragment to obtain a target interface document;
[0043] The use case update module is used to perform use case update processing on the existing use case set of the specified interface based on the target interface document to obtain a target use case set.
[0044] A third aspect of an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the computer device implements the method described in the first aspect above.
[0045] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect above is implemented.
[0046] A fifth aspect of the embodiments of the present application provides a computer program product, including a computer program, and when the computer program is executed, the method described in the first aspect above is executed.
[0047] The first aspect of the embodiment of the present application is that by obtaining the target code snippet associated with the specified interface, it is possible to accurately reflect the difference between the current interface code and the target interface code after the change, thereby providing a solid foundation for the update processing of the current interface document and the existing test case. Since the target code snippet is obtained by code change processing of the current interface code, the use case processing process can focus on the part that has actually changed, thereby improving the pertinence and efficiency of the test case processing. By the document update processing for the current interface document, it is possible to ensure that the interface document is consistent with the target code snippet, avoiding errors caused by the inconsistency between the interface document and the actual implementation. By the use case update processing for the existing use case set, it is possible to ensure that the test case is consistent with the updated interface document. Through the document update processing and the use case update processing, the consistency between the interface code, the interface document and the test case is achieved, thereby improving the accuracy and effectiveness of the test case.
[0048] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0050] Figure 1 It is a flowchart of the implementation of the interface test case processing method provided in the embodiment of the present application;
[0051] Figure 2 It is a flowchart of the implementation of the document update processing method provided in the embodiment of the present application;
[0052] Figure 3 It is a flowchart of the implementation of the use case update processing method provided in the embodiment of the present application;
[0053] Figure 4 It is a flow chart of the implementation of the method for generating a target test case provided in an embodiment of the present application;
[0054] Figure 5 It is a flow chart of the implementation of the matching method of the specified use case template provided in the embodiment of the present application;
[0055] Figure 6 is a flow chart for implementing the change identification method provided in the embodiment of the present application;
[0056] Figure 7 is a flowchart of the method for obtaining a target code fragment provided in an embodiment of the present application;
[0057] Figure 8 is a flowchart of an implementation of an interface testing method provided in an embodiment of the present application;
[0058] Fig. 9 This is a specific implementation flow chart of the interface testing method provided in the embodiment of the present application;
[0059] Fig.10 It is a flow chart for implementing the automated interface testing method provided in the embodiment of the present application;
[0060] Fig.11 is a schematic diagram of an interface test case processing device provided in an embodiment of the present application;
[0061] Fig.12 It is a schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0062] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0063] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, processes, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, processes, elements, components and / or combinations thereof.
[0064] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0065] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0066] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0067] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0068] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0069] 1) Application Programming Interface (API), also known as application program interface, or interface for short, is a way for software to communicate with each other. It defines how software components should interact, including libraries, operating systems, microservices, or remote servers. API provides a way for developers to use predefined functions without understanding or accessing the internal code. API can be used to build and integrate various applications and services.
[0070] 2) Interface testing, also known as API testing, is a very important task in the software development process. 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. The interface code is the actual program code that implements the API function. It contains the specific implementation of operations such as processing requests, executing business logic, accessing databases, or calling other services. The application programming interface document (Application Programming Interface Documentation) is a technical document that describes how to use and integrate an API. It is also called an interface document. It usually includes the API's functions, endpoints, request methods, request parameters, response formats, sample codes, etc. A good API document can help developers quickly understand and use the API and improve development efficiency. The interface use case is the test case of the interface. It is a series of input and output pairs designed to verify whether the behavior of the API meets expectations, including forward testing (normal conditions) and reverse testing (abnormal conditions).
[0071] In the application, in the management and scheduling scenarios of heterogeneous computing resources, a series of pre-dependent initialization tasks must be completed before the resources are managed, such as the entry of data center, computer room and cabinet information and the listing of servers. These operations must be implemented through API calls, and before the functions are officially delivered to customers, testers need to conduct comprehensive interface tests on each API to ensure that they function properly. Interface testing must not only verify successful scenarios (such as successful server listing), but also cover a variety of failure scenarios and possible abnormal situations, such as cabinet U-position conflicts, server mandatory information errors, or field values exceeding the boundary. Currently, testers manually write test cases based on the interface documents provided by the developer. This process has many problems: first, writing test cases is tedious, time-consuming and error-prone; second, when the API interface changes, the use cases and documents need to be manually maintained, which increases the heavy workload; finally, if the information of the interface changes is not communicated to the person in charge of the relevant module in a timely manner, it may lead to a series of errors such as script execution, use case updates and document maintenance.
[0072] In addition, existing API testing methods mainly rely on manually written test cases, which are inefficient and prone to errors. When the API interface changes, the test cases need to be rewritten or modified, which not only increases the workload of development and maintenance, but also easily leads to omissions or inconsistencies. Although some automated testing tools (such as Postman and JMeter) provide automated testing functions, they still rely on manual settings and configurations by developers and cannot automatically generate test cases based on the specific description of the API (such as field type, length range, permission restrictions, etc.), which further limits the efficiency and accuracy of testing.
[0073] Based on this, an embodiment of the present application provides an interface test case processing method, which can achieve consistency among the interface code, interface document and interface use case of the same interface, and improve the accuracy and timeliness of the test case.
[0074] In one embodiment, Figure 1 As shown, a method for processing an interface test case is provided, and the method is applied to a computer device running an automated testing tool as an example for description, including the following steps S101 to S103:
[0075] Step S101 : obtaining a target code segment associated with a specified interface, where the target code segment represents the difference between a current interface code of the specified interface and a target interface code obtained after code modification.
[0076] In the application, the designated interface refers to the application interface that needs to be processed with an interface use case. Each application interface is associated with at least an interface code and an interface document. In a test environment, the application interface is also associated with an interface use case (i.e., a test case of the interface). The current interface code represents the interface code of the designated interface without code changes. The developer performs code changes on the current interface code of the designated interface to obtain the target interface code. The difference between the target interface code and the current interface code is the target code fragment. In the case of changes to the current interface code of the designated interface, the automated testing tool needs to update the current interface document and the current interface use case of the designated interface according to the target code fragment in the target interface code of the designated interface to ensure the consistency among the interface code, interface document, and interface use case of the designated interface.
[0077] In the application, the target code snippet can be obtained in real time. The automated testing tool uses the version control tool to capture the submission operation of the change processing of the interface code of the specified interface, and then reads the changed code snippet corresponding to the corresponding code change processing operation according to the interface name of the specified interface.
[0078] Step S102: Based on the target code snippet, the current interface document of the specified interface is updated to obtain the target interface document.
[0079] In applications, interface documents are usually used to describe information such as the structure, endpoints, request and response formats of the interface. Interface documents are usually stored in preset formats, such as JSON and YAML. When the current interface code of a specified interface changes, the automated testing tool captures the target code snippet in the interface code, parses the target code snippet, and uses the same preset format as the interface document to represent the changed content. The document service that maintains the interface document is called to update the current interface document of the specified interface to obtain the target interface document. The document update based on the target interface code ensures that the target interface document is consistent with the target interface code.
[0080] In the application, if the code change of the current interface code involves the basic information of the API, such as version information, description, etc., then update the basic information in the current interface document. If the code change of the current interface code involves version update, then update the version number and version description in the interface document. If the code change of the current interface code involves changes in the authentication or authorization mechanism, it is necessary to update the authentication mechanism description or authorization description in the interface document. If the code change of the current interface code involves the data format of the interface request or response, then update the request format description or response format description in the interface document. If the code change of the current interface code involves changes in the error handling mechanism in the interface, then update the corresponding document. For error codes, if there are new error codes, add them to the interface document; if there are error codes that are removed, remove them from the document. For modifications to the error response format, update the error response format description in the document. If the modification involves changes in restrictions such as request frequency and size, then update the restriction description such as request frequency and size. If the modification results in changes in the sample code, then the sample code in the document needs to be updated.
[0081] In the application, the document update processing for the current interface document can ensure that when the interface code of the specified interface changes, the current interface document of the specified interface can be updated in time, ensuring the consistency of the interface document and interface code of the specified interface.
[0082] Step S103: Based on the target interface document, a use case update process is performed on the existing use case set of the specified interface to obtain a target use case set.
[0083] In the application, the existing use case set of the specified interface includes multiple test cases for testing the interface code before the change. The automated testing tool compares the target interface document with the current interface document through the version control tool, identifies the change points, and performs use case update processing on the existing use case set according to the change points, that is, updates the existing use cases and combines them to obtain the target use case set for testing the target interface code after the code change. Among them, the change point is a data structure that uses a preset format to describe the content that has changed in the current interface document. The preset format can be JSON, YAML, etc.
[0084] In the application, the specified interface provides at least one data function, such as adding, deleting, modifying and querying. The code change of the specified interface is essentially a change to the data function. Accordingly, the target interface document includes detailed descriptions of various new, deleted or modified functions. For new functions, the change points can be determined by checking whether new endpoints are added in the target interface document, or checking whether new functions or parameters are added to existing endpoints in the target interface document. For deleted functions, the change points can be determined by checking whether endpoints are removed in the target interface document, or checking whether certain functions or parameters are deleted from existing endpoints. For modified functions, the change points can be determined by checking whether the path, request method, request parameters, etc. of existing endpoints in the target interface document have been changed, or checking whether the function implementation, request parameters, response format, etc. of existing endpoints have been changed.
[0085] In the application, after determining the change point, update the existing use case set accordingly according to the change point to obtain the target use case set. If the change point is generated by adding a new function in the specified interface, write a new test case based on the new function and ensure that the new test case covers all the new functions. If the change point is generated by modifying the existing function in the specified interface, update the existing test case according to the modified function and ensure that the modified test case can still be executed correctly. If the change point is generated by deleting the existing function in the specified interface, delete the test case related to the modified function from the existing use case set and ensure that the deleted test case will not affect the execution of other test cases. Finally, integrate the updated test cases into the new test set to obtain the target use case set of the specified interface. The generated target use case set can meet the following requirements to ensure that all new functions are covered, all modified functions are updated correctly, and functions that have not been deleted can still be tested.
[0086] In this embodiment, by obtaining the target code snippet associated with the specified interface, it can be ensured that the use case processing process is implemented based on the latest code changes. Since the target code snippet is obtained by editing the current interface code, the use case processing process can focus on the part that actually changes, thereby improving the pertinence and efficiency of the test case processing. By performing a document update process on the current interface document, it can be ensured that the interface document is consistent with the target code snippet, avoiding misunderstandings or errors caused by inconsistencies between the document and the actual implementation. By performing a use case update process on an existing use case set, it can be ensured that the test case is consistent with the updated interface document. Through document update processing and use case update processing, consistency between the interface code, interface document and test case is achieved, thereby improving the accuracy and effectiveness of the test case.
[0087] In one embodiment, Figure 2 As shown, Figure 1The implementation process of step S102 includes the following steps S201 to S202:
[0088] Step S201: locate the position of the specified interface in the current interface document based on the interface name of the specified interface.
[0089] In the application, the automated testing tool executes document update processing for the current interface document. First, the position information of the specified interface in the current interface document is located according to the interface name of the specified interface. The position includes the start position and the end position.
[0090] Step S202, based on the target code snippet, update the document content at the location to obtain the target interface document.
[0091] In the application, the automated testing tool parses the target code snippet and generates a change point that conforms to the preset format. A change point is a data structure used to describe the changes in the specified interface. The change point includes the changes in endpoints, request parameters, response formats, exception handling, and other factors. Parse the change point in the preset format, and update the document content between the start position and the end position in the current interface document according to the change point to obtain the target interface document.
[0092] This embodiment can ensure that the target interface document is consistent with the target interface code, effectively avoiding misunderstandings or errors caused by delayed modification of the interface document, thereby improving the accuracy and reliability of the document.
[0093] In one embodiment, Figure 3 As shown, Figure 1 The implementation process of step S103 includes the following steps S301 to S304:
[0094] Step S301, reading target content adapted to the target code snippet in the target interface document.
[0095] In the application, the target content is essentially the document content of the target interface document that has changed relative to the current interface document. The target content is used to describe in the target interface document the information that is compatible with the target code fragment in the target interface code.
[0096] Step S302: identify changes in the target content to obtain at least one change point.
[0097] In the application, a change point is a data structure that uses a preset format to describe the content that has changed in the current interface document. The target content includes the description information of at least one change point. Parsing the target content can generate change points in a preset format. The automated testing tool parses the target content, identifies changes in the target content according to the preset identification elements, and obtains one or more change points that conform to the preset format. The identification elements may include endpoints, request parameters, response formats, exception handling mechanisms, interface types, field information, lengths, descriptions, etc.
[0098] Step S303: generating target test cases for each change point based on the change point.
[0099] In the application, constraints refer to the specific constraint information for the value of the identification element corresponding to the change point. Constraints include: data type, length limit, required items, default values, etc. of request parameters; data type, format, status code, etc. of the response format; error response and exception handling logic required for exception handling. The automated testing tool generates corresponding test cases based on the constraints of the change point. The automated testing tool generates target test cases that are adapted to each change point based on the preset constraints. The target test cases are used to test the changed content in the target interface code.
[0100] Step S304: based on each target test case, update the existing use case set of the specified interface to obtain the target use case set.
[0101] In the application, the existing use case set of the specified interface includes at least one test case for testing the current interface code (without code changes). In the case of changes in the interface code, a target test case is generated to test the changed content. Based on the target test case, the existing use case set of the specified interface is updated to obtain a target use case set that can test the target interface code of the specified interface. The use case update for the existing use case set includes the process of deleting existing use cases that are not compatible with the target interface document, or adding new target test cases.
[0102] In this embodiment, it is possible to ensure that the test cases are consistent with the latest interface documents, effectively verify new or modified functions, avoid introducing new defects due to code changes, and improve software quality and test coverage.
[0103] In one embodiment, Figure 4 As shown, Figure 3 The implementation process of step S303 includes the following steps S401 to S402:
[0104] Step S401, based on a preset use case template library, determine the designated use case template for each change point.
[0105] In the application, the preset use case template library includes at least one use case template, and the use case template may include a use case template for testing boundary range, a use case template for testing content length, etc. The automated testing tool may generate test cases based on the use case templates in the preset use case template library. First, the automated testing tool searches for a specified use case template that matches the change point from the preset use case template library. If the specified use case template does not exist in the use case template library, a new use case template may be created first.
[0106] Step S402: generating target test cases for each change point based on each change point and the designated test case template for each change point.
[0107] In the application, the automated testing tool generates a target test case for each change point based on the actual content of the change point and the corresponding specified test case template.
[0108] In this embodiment, test cases that meet the requirements of the specified interface after the change can be efficiently generated, ensuring the comprehensiveness and accuracy of the test, while reducing the workload of manually writing test cases, improving test efficiency and software quality.
[0109] In one embodiment, Figure 5 As shown, Figure 4 The implementation process of step S401 includes the following steps S501 to S503:
[0110] Step S501, respectively matching the use case template of each change point in the preset use case template library.
[0111] In the application, the change point includes the change type. The automated testing tool searches for a use case template that matches the change type in the use case template library, and determines the specified use case template for the change point based on the search result. The search result is used to indicate whether there is a use case template that matches the change type of the change point in the use case template library.
[0112] Step S502: for any change point, if there is no existing use case template matching the change point, a new use case template for the change point is created as a designated use case template for the change point.
[0113] In the application, for each change point, if an existing use case template cannot be found in the use case template library, a new use case template matching the change point can be created first as the designated use case template for the change point.
[0114] Step S503: for any change point, if there is an existing use case template matching the change point, the existing use case template is used as the designated use case template for the change point.
[0115] In the application, for each change point, if an existing use case template can be found in the use case template library, the existing use case template can be used as the designated use case template for the change point.
[0116] In this embodiment, it is possible to ensure that each change point has targeted test coverage, while reducing duplication of work and improving the efficiency and accuracy of test case generation.
[0117] In one embodiment, if any specified use case template is a new use case template, the specified use case template is stored in the use case template library; for any change point, if there is an existing test case for the change point, the existing test case is determined as the target test case for the change point.
[0118] In the application, if the specified use case template is a new use case template, storing the specified use case template in the use case template library can ensure the integrity and timeliness of the use case template library. At the same time, if there are existing test cases for the change point, the existing test cases can be directly used as the target test cases for the change point. In this way, the reusability of the test cases can be improved.
[0119] In one embodiment, Figure 6 As shown, Figure 3 The implementation process of step S302 includes the following steps S601 to S602. Among them:
[0120] Step S601 : Based on preset identification elements, changes are identified on the target content, and the associated content for each identification element is determined.
[0121] In the application, the target content is the content of the target interface document of the specified interface that has changed relative to the current interface document. The target content represents the content difference between the target interface document and the current interface document. The automated testing tool reads the associated content of each identification element from the target content. The identification element can be the return value type of the interface, the field information (length, type, value range) in the interface, etc. The target content is identified for changes to obtain the associated content of the identification element. For example, if the identification element is a field, its associated content is the value range of the field, etc.
[0122] Step S602: determining at least one change point of the designated interface based on the associated content of each identification element.
[0123] In the application, the automated testing tool parses the associated content of each identified element and generates corresponding change points.
[0124] In this embodiment, the details of the interface changes can be accurately captured, ensuring the accurate identification and positioning of each change point, thereby improving the pertinence and effectiveness of the test.
[0125] In one embodiment, Figure 7 As shown, Figure 1 The implementation process of step S101 includes the following steps S701 to S703. Among them:
[0126] Step S701: Obtain a change identifier, where the change identifier is used to indicate an interface whose interface code has been changed.
[0127] In the development environment of a specified interface, all codes associated with the application that calls the specified interface are usually managed using version control tools. Based on this, the automated testing tool can capture the submission operation of the code change processing for the interface code based on the version control tool. If the submission operation of the code change processing can be captured, it means that there is a change in the interface code. During each submission operation after the code change processing, the changed code fragment can be marked with a change identifier to facilitate subsequent interface search through the change identifier.
[0128] In the application, there is an association between the change identifier and the application program interface. The change identifier indicates the application program interface that has changed. The application program interface can be identified by the interface name.
[0129] Step S702: Determine a target change identifier of the designated interface from among the change identifiers based on the interface name of the designated interface.
[0130] In the application, the interface name of the specified interface is used as an index, and a target change identifier that matches the interface name is searched in the existing change identifiers.
[0131] Step S703: determining a target code segment associated with the specified interface based on the target change identifier.
[0132] In the application, the automated testing tool can obtain the changed code snippet, that is, the target code snippet, from the existing code snippet of the specified interface according to the target change identifier.
[0133] This embodiment can efficiently identify the specific location and content of the interface change, ensuring the accuracy and efficiency of subsequent test case updates and verifications.
[0134] In one embodiment, Figure 8 As shown, based on Figure 1 After the interface test case processing method shown obtains the target case set, the following steps S104 to S105 may be further performed:
[0135] Step S104, performing consistency verification processing on the target interface code, target interface document and target use case set of the specified interface to obtain a verification result, wherein the target interface code includes the target code fragment.
[0136] In the application, in order to ensure that the target interface code, target interface document and target use case set of the specified interface are consistent in the test environment, the automated testing tool usually needs to perform consistency verification. The following consistency verification process is performed for the target interface code and target interface document of the specified interface: 1) Parse the target interface document and extract the description information of the specified interface. The target interface document describes in detail the functions, endpoints, request parameters, response format and other information of the interface after the code change. 2) Compare the target interface code with the target interface document, and write a script to compare the relevant information of the specified interface described in the target interface document with the actual implemented target interface code to ensure that the two are consistent. Among them, first check the endpoint to confirm that all endpoints listed in the target interface document exist in the target interface code, and the path and method (such as GET, POST, etc.) of the endpoint match. Secondly, check the request parameters to ensure that the request parameters (such as path parameters, query parameters, request body, etc.) described in the target interface document are consistent with the parameters required in the target interface code. Thirdly, check the response format to verify that the response format (such as status code, response body, etc.) defined in the target interface document is consistent with the response returned in the target interface code. Finally, check the exception handling to confirm that the exception handling mechanism (such as error code, error message, etc.) mentioned in the target interface document is consistent with the exception handling logic in the target interface code.
[0137] Step S105: If the consistency check process passes, an interface test is performed on the specified interface based on the target use case set to obtain a test result.
[0138] In the application, if the consistency check passes, the interface test is performed on the specified interface based on the test case set. The test process is as follows: First, prepare the test environment, that is, ensure that the interface can run normally in the test environment. Execute the test, that is, use the automated testing tool to execute the test cases in the test case set and record the test results.
[0139] In this embodiment, consistency verification is used to ensure the consistency among the code, documents and use case set; on the premise that the verification passes, the specified interface is tested based on the target use case set to obtain reliable test results, effectively ensuring the correctness and stability of the interface.
[0140] In one embodiment, Fig. 9 As shown, the implementation process of step S105 includes the following steps S801 to step S802.
[0141] Step S801, generating a test script corresponding to a target use case set.
[0142] In the application, the automated testing tool writes automated test scripts based on the target test case set. The test script includes at least test data (providing the input data required for the test), test steps (defining the execution steps of the test), and expected results (defining the expected results of each test case).
[0143] Step S802, run the test script, perform interface test on the specified interface, and obtain the test result.
[0144] In the application, the automated testing tool runs the test script to perform interface testing for the specified interface to obtain the test results. The script can be run through the command line.
[0145] This embodiment can not only improve the efficiency of the test, but also ensure the accuracy and repeatability of the test.
[0146] In one embodiment, Fig.10 As shown, in the test environment, the automated testing tool detects the submission event of the editing process of the interface code of any interface in real time through the version control tool, perceives the change of the interface code in real time, and updates the current interface document and the existing use case set by modifying the instruction to complete the interface test case processing process. The specific implementation process of the use case processing method for any specified interface includes the following steps S901 to S910:
[0147] Step S901: If a submission operation for code change processing of an interface code is detected, a first modification instruction is sent to a document service.
[0148] In the application, the detection service of the automated testing tool detects a submission operation of a code change process for the interface code of the specified interface, obtains a target code snippet, and the target code snippet represents the difference between the current interface code of the specified interface and the target code interface after the code change, and adds a first identifier to the target code snippet. At the same time, a first modification instruction carrying the first identifier and the interface name of the specified interface is generated, and the first modification instruction is sent to a document service for maintaining interface documents.
[0149] Step S902: The document service receives the first modification instruction and locates the starting position and the ending position of the specified interface in the current interface document according to the interface name carried in the first modification instruction.
[0150] And mark the second change indicator in the existing document.
[0151] Step S903: The document service updates the specified document content between the start position and the end position in the current interface document according to the first modification instruction, obtains the target interface document, and sends a second modification instruction carrying the interface name to the use case library service that maintains the use case library.
[0152] Step S904: The use case library service receives the second modification instruction, identifies changes to the target interface document according to the interface name, and obtains change points in a preset format.
[0153] Step S905: The use case library service determines whether there is a specified use case template adapted to the change point in the use case template library. If yes, step S906 is executed; if no, step S908 is executed.
[0154] In the application, the use case library service receives the second modification instruction and performs parsing to determine whether there is a matching use case template in the use case template library. If there is, the existing use case template is used to regenerate the use case and overwrite the existing interface use case. If there is no existing use case template, a new use case template is added to generate a new interface use case.
[0155] Step S906: Generate target test cases of the change points according to the specified test case template.
[0156] Step S907, overwrite the existing test cases.
[0157] Step S908: Add a use case template that is adapted to the change point to obtain a specified use case template.
[0158] Step S909: adding the newly added use case template to the use case template library.
[0159] Step S910: Generate test cases for change points according to the newly added test case template.
[0160] It should be noted that in order to ensure the consistency between the target interface code after the code change and the updated interface document and interface use case, a consistency check can be performed. The specific verification process is as described in the above step S104 and will not be repeated here.
[0161] In this embodiment, the submission operation of the code change processing for the interface code is detected in real time, and the change of the interface code can be perceived in time. Then, the interface document and interface use case are updated based on the changed code fragment to ensure the accuracy of the test case, and after passing the consistency check, the interface test is performed, which can test the efficiency and accuracy of the test results and reduce maintenance costs.
[0162] The present application also provides an interface test case processing device for executing the steps in the above interface test case processing method embodiment. Fig.11 As shown, the interface test case processing device 1000 provided in the embodiment of the present application includes:
[0163] The acquisition module 1010 is used to acquire a target code segment associated with a specified interface, where the target code segment represents the difference between a current interface code of the specified interface and a target interface code obtained after code modification.
[0164] The document updating module 1020 is used to perform document updating processing on the current interface document of the specified interface based on the target code fragment to obtain the target interface document.
[0165] The use case update module 1030 is used to perform use case update processing on the existing use case set of the specified interface based on the target interface document to obtain the target use case set.
[0166] In one embodiment, the document update module is also used to locate the position of the specified interface in the current interface document based on the interface name of the specified interface; based on the target code fragment, update the document content at the position to obtain the target interface document.
[0167] In one embodiment, the use case update module is also used to read the target content in the target interface document that is adapted to the target code snippet; identify changes in the target content to obtain at least one change point, where the change point is used to describe the changed content in the current interface document in a preset format; generate target test cases for each change point based on the change point; and based on each target test case, update the existing use case set of the specified interface to obtain a target use case set.
[0168] In one embodiment, the use case update module is also used to determine the designated use case template for each change point based on a preset use case template library; based on each change point and the designated use case template for each change point, generate a target test case for each change point.
[0169] In one embodiment, the use case update module is also used to match the use case templates of each change point in a preset use case template library; for any change point, if there is no existing use case template that matches the targeted change point, a new use case template for the targeted change point is created as the designated use case template for the targeted change point; for any change point, if there is an existing use case template that matches the targeted change point, the existing use case template is used as the designated use case template for the targeted change point.
[0170] In one embodiment, the use case update module is also used to store any specified use case template into the use case template library if any specified use case template is a new use case template; for any change point, if there is an existing test case for the change point, the existing test case is determined as the target test case for the change point.
[0171] In one embodiment, the use case update module is further used to identify changes in the target content based on preset identification elements, determine the associated content for each identification element; and determine at least one change point of the specified interface based on the associated content of each identification element.
[0172] In one embodiment, the acquisition module is also used to obtain a change identifier, which is used to indicate the interface whose interface code has changed; based on the interface name of the specified interface, determine the target change identifier of the specified interface from each change identifier; based on the target change identifier, determine the target code fragment associated with the specified interface.
[0173] In one embodiment, the use case update module is also used to perform consistency verification on the target interface code, target interface document and target use case set of the specified interface to obtain the verification result, and the target interface code includes the target code fragment; if the consistency verification process passes, the interface test is performed on the specified interface based on the target use case set to obtain the test result.
[0174] In one embodiment, the use case update module is further used to generate a test script corresponding to the target use case set; run the test script, perform interface testing on the specified interface, and obtain test results.
[0175] In application, each module in the interface test case processing device may be a software program module, or may be implemented by different logic circuits integrated in a processor, or may be implemented by multiple distributed processors.
[0176] Fig.12 A schematic diagram of the structure of a computer device for implementing an interface test case processing method provided by an embodiment of the present application. Fig.12 As shown, the computer device 1100 of this embodiment includes: at least one processor 1110 ( Fig.12 Only one is shown in the figure) a processor, a memory 1120, and a computer program 1130 stored in the memory 1120 and executable on the at least one processor 1110, wherein the processor 1110 implements the steps of any of the above-mentioned robot control method embodiments when executing the computer program 1130.
[0177] The computer device 1100 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device 1100 may include, but is not limited to, a processor 1110 and a memory 1120. Those skilled in the art will appreciate that Fig.12 The computer device 1100 is merely an example and does not constitute a limitation on the computer device 1100 . The computer device 1100 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device 1100 may also include input and output devices, network access devices, etc.
[0178] The processor 1110 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0179] In some embodiments, the memory 1120 may be an internal storage unit of the computer device 1100, such as a hard disk or memory of the computer device 1100. In other embodiments, the memory 1120 may also be an external storage device of the computer device 1100, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 1100. Further, the memory 1120 may also include both an internal storage unit of the computer device 1100 and an external storage device. The memory 1120 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program, etc. The memory 1120 may also be used to temporarily store data that has been output or is to be output.
[0180] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0181] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0182] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0183] An embodiment of the present application provides a computer program product. When the computer program product runs on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0184] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0185] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0186] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0187] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0188] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0189] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for processing an interface test case, characterized in that: Methods include: Acquire a target code segment associated with a specified interface, wherein the target code segment represents a difference between a current interface code of the specified interface and a target interface code obtained after code change; Based on the target code snippet, updating the current interface document of the specified interface to obtain a target interface document; Based on the target interface document, use case update processing is performed on the existing use case set of the designated interface to obtain a target use case set.
2. The interface test case processing method according to claim 1, characterized in that: The step of performing document update processing on the current interface document of the specified interface based on the target code fragment to obtain the target interface document includes: Based on the interface name of the specified interface, locate the position of the specified interface in the current interface document; Based on the target code fragment, the document content at the position is updated to obtain the target interface document.
3. The interface test case processing method according to claim 1, characterized in that: The step of performing use case update processing on the existing use case set of the specified interface based on the target interface document to obtain the target use case set includes: Reading target content adapted to the target code fragment in the target interface document; Performing change identification on the target content to obtain at least one change point, wherein the change point is used to describe the changed content in the current interface document in a preset format; Generating target test cases for each of the change points based on the change points; Based on each of the target test cases, the current test case set of the specified interface is updated to obtain a target test case set.
4. The interface test case processing method according to claim 3, characterized in that: Generating target test cases for each of the change points based on the change points includes: Determine the designated use case template for each of the change points based on a preset use case template library; Based on each of the change points and the designated test case template of each of the change points, a target test case for each of the change points is generated.
5. The interface test case processing method according to claim 4, characterized in that: The step of determining the designated use case template for each change point based on a preset use case template library includes: In the preset use case template library, respectively match the use case template of each change point; For any of the change points, if there is no existing use case template matching the change point, a new use case template for the change point is created as a designated use case template for the change point; For any of the change points, if there is an existing use case template that matches the change point, the existing use case template is used as the designated use case template for the change point.
6. The interface test case processing method according to claim 4 or 5, characterized in that: The method further comprises: If any of the specified use case templates is a new use case template, storing the specified use case template in the use case template library; For any of the change points, if there is an existing test case for the change point, the existing test case is determined as a target test case for the change point.
7. The interface test case processing method according to claim 3, characterized in that: The step of identifying changes in the target content to obtain at least one change point includes: Based on the preset identification elements, the target content is identified for changes, and the associated content for each identification element is determined; At least one change point of the designated interface is determined based on the associated content of each of the identification elements.
8. The interface test case processing method according to any one of claims 1 to 5, characterized in that: The step of obtaining the target code fragment associated with the specified interface includes: Obtain a change identifier, where the change identifier is used to indicate an interface whose interface code has changed; Based on the interface name of the designated interface, determining a target change identifier of the designated interface from each of the change identifiers; Based on the target change identifier, a target code segment associated with the designated interface is determined.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the computer device is caused to implement the method according to any one of claims 1 to 8.
10. A computer program product, characterized in that The invention comprises a computer program, which, when being executed, enables the method according to any one of claims 1 to 8 to be performed.
Citation Information
Patent Citations
Interface document updating method and device, electronic equipment and storage medium
CN110321142A
Interface document generation method, apparatus and device, and computer storage medium
CN110955416A
Method for automatically generating interface test case
CN116010287A
Joint debugging test method and device, computer equipment and storage medium
CN116028346A
Updating method of interface test case and related equipment
CN116257438A