Test method and device
By analyzing the code submission records and call relationships, identifying and testing interfaces affected by code changes, the problem of incomplete coverage affected by code changes is solved, and the accuracy and completeness of the test is improved.
Patent Information
- Application Number
- CN202411524225.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-02-25
AI Technical Summary
During the code change process of software or business system, it is difficult to fully cover the interface affected by code changes, which affects the accuracy and completeness of the test.
By obtaining code submission records, identifying code change files, and performing call relationship analysis on these files to identify the target interface affected by code changes. Then, look for the target test cases associated with the target interface from the existing test cases and test based on these test cases.
Ensures full coverage of interfaces affected by code changes, improving the accuracy and completeness of testing, especially in the case of increased software complexity.
Smart Images

Figure CN119512941A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of testing technology, and in particular to a testing method and device. Background Art
[0002] In order to improve the performance of software or business systems, it is usually necessary to change the code, such as fixing vulnerabilities, adding new features, optimizing performance, adjusting compatibility, etc. Therefore, it is necessary to track the impact of code changes. Summary of the invention
[0003] The present application aims to solve one of the technical problems in the related art at least to some extent.
[0004] To this end, the first purpose of this application is to propose a testing method.
[0005] The second objective of the present application is to provide a testing device.
[0006] The third objective of the present application is to provide an electronic device.
[0007] A fourth objective of the present application is to provide a computer-readable storage medium.
[0008] A fifth object of the present application is to provide a computer program product.
[0009] To achieve the above-mentioned purpose, the first embodiment of the present application proposes a testing method, including:
[0010] Get code submission records;
[0011] Determine a code change file based on the code submission record;
[0012] Performing call relationship analysis on the code change file to determine the target interface affected by the code change; wherein the target interface refers to the externally exposed interface affected by the code change;
[0013] Searching for a target test case associated with the target interface from existing test cases;
[0014] Perform a test based on the target test case and obtain a test result.
[0015] To achieve the above-mentioned purpose, the second embodiment of the present application proposes a testing device, including:
[0016] The first acquisition module is used to acquire code submission records;
[0017] A first determination module, configured to determine a code change file based on the code submission record;
[0018] A second determination module is used to perform call relationship analysis on the code change file to determine the target interface affected by the code change; wherein the target interface refers to the externally exposed interface affected by the code change;
[0019] A search module, used to search for a target test case associated with the target interface from existing test cases;
[0020] The test module is used to perform a test based on the target test case and obtain a test result.
[0021] To achieve the above-mentioned purpose, the third aspect of the present application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0022] The memory stores computer-executable instructions;
[0023] The processor executes the computer-executable instructions stored in the memory to implement the method as described in the embodiment of the first aspect.
[0024] To achieve the above-mentioned purpose, the fourth aspect embodiment of the present application proposes a computer-readable storage medium, in which computer-readable storage medium is stored computer execution instructions, and when the computer execution instructions are executed by a processor, they are used to implement the method described in the first aspect embodiment.
[0025] To achieve the above-mentioned purpose, the fifth aspect of the present application proposes a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.
[0026] The test method, device, electronic device and storage medium provided by the present application determine the code change file according to the code submission record, determine the target interface affected by the code change by performing call relationship analysis on the code change file, and search for the target test case associated with the target interface from the existing test cases, and then test based on the target test case. Thus, based on the code submission record, the interface affected by the code change is identified, and based on the affected interface, a suitable test case is searched from the existing test cases, which can ensure full coverage of the affected area, improve the accuracy of the test, and ensure the completeness and quality of the test scenario when the software complexity increases.
[0027] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0029] Figure 1 A flow chart of a testing method provided in an embodiment of the present application;
[0030] Figure 2 A schematic diagram of another testing method provided in an embodiment of the present application;
[0031] Figure 3 A schematic diagram of another testing method provided in an embodiment of the present application;
[0032] Figure 4 A schematic diagram of the structure of a testing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0034] The testing method and device of the embodiments of the present application are described below with reference to the accompanying drawings.
[0035] Figure 1 A flow chart of a testing method provided in an embodiment of the present application.
[0036] In some embodiments, interfaces affected by code changes can be manually tracked. However, with the increasing system complexity, manually tracking the impact of code changes on interfaces becomes increasingly difficult, which can easily lead to test omissions and affect test accuracy.
[0037] To address this problem, the present application provides a testing method, such as Figure 1 As shown, the test method includes the following steps:
[0038] Step 101, obtaining code submission records.
[0039] In this application, the code can be managed through a distributed version control system. When the user writes or changes the code, the code can be submitted. The distributed version control system can record each submission, thereby obtaining a code submission record.
[0040] The code submission record may include but is not limited to submission information, author, date, changed code files, etc.
[0041] Step 102: Determine the code change file based on the code submission record.
[0042] In this application, based on the code submission record, the submission that needs to be analyzed can be obtained, and then the code files involved in the submission can be determined. Here, the code files involved in the submission are code change files. There can be one or more code change files.
[0043] Taking git as an example, we can save the commit-hash-last value of the most recent code association analysis in the current code repository, and execute git log <commit-hash-last> .. <commit-hash-now>The command can obtain the commit-hash values of all commits between the last analyzed commit and the latest commit, and then execute git show for each commit <commit-hash>Determine the code files involved in this submission, that is, determine the code change files.
[0044] Step 103: Perform call relationship analysis on the code change file to determine the target interface affected by the code change.
[0045] The target interface may refer to an externally exposed interface affected by the code change.
[0046] For example, if the programming language used in the code change file is Java, the call relationship analysis of the code change file can be performed until the *java file containing the setting annotation or ending with API is found, and all the externally exposed interfaces affected by the code change are obtained. For example, the setting annotation can be @RestController.
[0047] Exemplarily, for each code change file, the Java-all-call-graph component can be used to analyze the call relationship until the *.java file containing the @RestController annotation or ending with Api is found, that is, all the externally exposed interfaces affected by the code file change are obtained. Exemplarily, the Java-all-call-graph component or similar tools can be used to build a call graph for the entire project, starting from the code change file, and analyzing all possible call chains along the call graph until the *.java file containing the @RestController annotation or ending with API is found.
[0048] Step 104: Search the target test case associated with the target interface from the existing test cases.
[0049] In the present application, each interface has a corresponding test case, and the target test case associated with the target interface can be found from the existing test cases by querying the association relationship between the interface and the test case according to the target interface.
[0050] Step 105: Perform a test based on the target test case and obtain a test result.
[0051] In this application, the target test case can be implemented as a test script, and the test is performed by executing the test script to obtain the test result.
[0052] Exemplarily, the test scripts involved can be added to the test plan, the test plan is executed, the test results are measured, and the pass rate is calculated as the gate for code check-in. In addition, after the test script is executed, the incremental code coverage can also be determined. If the incremental code coverage is higher than the threshold, check-in can be allowed. If the incremental code coverage is lower than the threshold, check-in is not allowed.
[0053] In the embodiment of the present application, the code change file is determined according to the code submission record, the target interface affected by the code change is determined by performing call relationship analysis on the code change file, and the target test case associated with the target interface is found from the existing test cases, and then the test is performed based on the target test case. Thus, based on the code submission record, the interface affected by the code change is identified, and based on the affected interface, a suitable test case is found from the existing test cases, which can ensure full coverage of the affected area, improve the accuracy of the test, and ensure the completeness and quality of the test scenario when the software complexity increases.
[0054] Figure 2 A flowchart of another testing method provided in an embodiment of the present application.
[0055] like Figure 2 As shown, the test method may include the following steps:
[0056] Step 201, obtaining code submission records.
[0057] In the present application, step 201 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.
[0058] Step 202: Determine the code change file based on the code submission record.
[0059] In the present application, step 202 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.
[0060] Step 203: Analyze the code change file to obtain a file structure table and a method call relationship table.
[0061] In this application, the code change file can be analyzed for code association relationships. In the process of analyzing the code association relationships, two parts of metadata can be obtained: one is the file structure table of methods and variables based on class files, and the other is the method call relationship table based on call relationships.
[0062] Exemplarily, the file structure table may be as shown in Table 1 below:
[0063] Table 1
[0064] file name Element Type Element Name Start line number End line number java file name Method or member variable Method or variable name
[0065] Exemplarily, the method call relationship table is shown in Table 2 below:
[0066] Table 2
[0067] Calling Class Calling Methods Called Class Called method
[0068] Step 204: Determine the element type affected by the code change according to the file structure table.
[0069] In this application, the name of the code file affected by the code change file and the affected line number can be determined based on the call relationship, and the element type affected by the code change in the affected code file can be determined by querying the structure table of the file. Among them, the affected element type may include methods, member variables, etc.
[0070] Step 205: In response to the element type being a method, the target interface is determined by querying a method call relationship table.
[0071] If the element type affected by the code change is a method, you can query the method call relationship table based on the name of the affected element and analyze the caller layer by layer until you find the top-level caller, which is the exposed interface. The exposed interface found here is the target interface.
[0072] If the element type affected by the code change is a member variable, analyze the line number where the member variable appears in the current code file, and determine the affected element type by querying the file structure table until all affected methods are obtained. For the affected methods, query the method call relationship to find the target interface affected by the code change.
[0073] Step 206: Search the target test case associated with the target interface from the existing test cases.
[0074] In the present application, step 206 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.
[0075] In this application, it is possible to support the use of different tools to write test cases into test scripts, and the maintained test cases have a unique representation, and the target test cases can be found according to the tools used.
[0076] As a possible implementation method, for tools that specify adding a custom annotation @caseId (test case ID, tested interface) at the top of the file, the annotation information in the test script corresponding to the existing test case can be obtained, and the correspondence between the test case and the interface can be extracted from the annotation information. Then, according to the target interface, the target test case can be determined by querying the correspondence.
[0077] Optionally, the annotation information can be implemented as a decorator, in which the association between the test case ID and the interface under test can be written into a library table. For example, when the test script is executed, the association can be automatically written into the library table by the decorator, so that the test case ID corresponding to the target interface can be found in the library table, that is, the target test case can be found.
[0078] A business system can contain multiple modules, a module can contain multiple test cases, a test case can contain multiple test steps, and the call to the interface in the test case is written in the test step. As another possible implementation method, when implementing the test case, a tool that manages the test case using a unified test step format title can first determine the target test step involved in the target interface, obtain the title of the target test step, and then analyze the title to determine the target test case.
[0079] Exemplarily, the configuration item of the interface call can be set to identify whether the request path contains the address of the target interface, thereby determining the test steps related to the target interface, that is, determining the target test steps.
[0080] Exemplarily, the title of a test step can be used to identify the correspondence between the test step and the test case. The title of the test step can include information about the test step and the test case, such as the identification of the test case, a description of the test step, etc., thereby determining the target test case from the title of the target test step.
[0081] For example, when implementing test cases, you can use a unified step title format: "[Test Case ID-Test Step Description]". This format ensures that the title of each test step clearly identifies the test case ID to which it belongs, making it easy to quickly identify and associate. In this way, once the test steps involved in the target interface are located, they can be traced back to their corresponding test cases.
[0082] Therefore, according to the tool used to write the test script, the target test case associated with the target interface can be found from the existing test cases in a corresponding manner, which improves the efficiency and accuracy of the target test case search and has strong applicability.
[0083] Step 207: Perform a test based on the target test case and obtain a test result.
[0084] In the present application, step 207 can be implemented in any of the embodiments of the present application, so it will not be described in detail here.
[0085] In this application, according to the code submission record, the interfaces affected by the code change and the test cases associated with the affected interfaces can be found, and the test plan can be constructed based on the found test cases. Among them, different test cases can be divided into different test sub-plans for parallel execution according to the different test result time requirements, and finally the test sub-plans can be merged to obtain the test results, thereby improving the test efficiency.
[0086] As a possible implementation method, the number of currently idle executors and the historical average execution time of each target test case can be determined. If the number of target test cases is greater than the number of currently idle executors, the target test cases are sorted in descending order according to the historical average execution time of the target test cases to obtain a test case list, the test case list is traversed, the target test cases are selected one by one from the test case list, and added to the group with the shortest historical average execution time, and the test is performed by executing the test sub-plan.
[0087] Among them, each idle execution machine is assigned a group, and each group corresponds to a test sub-plan, that is, the execution machine in each space can execute a test sub-plan, and the test results of each test sub-plan are merged to obtain the test result of this test.
[0088] The historical average execution time of a group may be the sum of the historical average execution times of target test cases in the current group.
[0089] Exemplarily, the specific steps of the test plan grouping algorithm may be as follows:
[0090] (1) Obtain the number of currently idle execution machines n and the historical average execution time of each target test case.
[0091] (2) If the number of test cases to be executed is less than the number of currently idle execution machines, the target test cases can be randomly assigned to the currently idle execution machines and the algorithm ends. Otherwise, execute step (3).
[0092] (3) Sort the target test cases by execution time from largest to smallest, and create n empty arrays to represent the n test sub-execution plans.
[0093] (4) Traverse the sorted test case list, select test cases from the list one by one, and add them to the execution plan group with the minimum execution time.
[0094] (5) Repeat step (4) until all test cases are assigned to a group.
[0095] Based on the above-mentioned allocation of test cases according to the historical average execution time of the test cases, the visual test cases to be executed can be effectively grouped so that the execution time of each group is relatively close, thereby making the execution end time of each test sub-execution plan similar, reducing the maximum execution time, which can not only balance the load of each execution machine, but also reduce the maximum execution time of the entire test plan, thereby improving test efficiency.
[0096] In the embodiment of the present application, the file structure table and the method call relationship table are obtained by analyzing the code change file. According to the file structure table, the element type affected by the code change is queried. If the element type is a method, the method call relationship is queried to find the target interface affected by the code change. Thus, based on the file structure table and the method call relationship table, the target interface is found by querying, which improves the search efficiency and accuracy.
[0097] Figure 3 A flowchart of another testing method provided in an embodiment of the present application.
[0098] like Figure 3 As shown, the test method may include the following steps:
[0099] Step 301, obtaining code submission records.
[0100] Step 302: Determine the code change file based on the code submission record.
[0101] Step 303: Perform call relationship analysis on the code change file to determine the target interface affected by the code change.
[0102] Step 304: Search the target test case associated with the target interface from the existing test cases.
[0103] Step 305: Perform a test based on the target test case and obtain a test result.
[0104] In the present application, steps 301 to 305 may be implemented in any of the embodiments of the present application, and therefore will not be described in detail herein.
[0105] Step 306 , in response to determining based on the test result that there is a code fragment not covered by the test, based on the call chain of the uncovered code fragment, obtain the code of each layer of the call chain.
[0106] In the present application, it is possible to determine whether there are code snippets that are not covered by the test based on the test results. If there are code snippets that are not covered by the test, the uncovered code snippets can be analyzed from the call chain, that is, the uncovered code snippet -> the function to which the uncovered code snippet belongs -> the function caller... -> the externally exposed interface layer, and extract the code of each layer of the call chain.
[0107] Step 307, based on the code of each layer of the call chain, using the large model, obtain the interface test scenario to be added.
[0108] In the present application, prompt words can be constructed based on the codes at each layer of the call chain, and the prompt words can be input into the large model so that the large model can analyze the interface test scenarios that may be missing, thereby obtaining the interface test scenarios to be added.
[0109] For example, in the incremental test results, there is the following code snippet, where lines 2-4 are not covered:
[0110]
[0111]
[0112] By analyzing the call chain of the above code snippet, we can see that the code snippet belongs to the method convertDate, which is called by the method userAdd in the service layer class UserService. The useAdd method is called by the userAdd interface in the API layer UserAPI. Find the method body of the corresponding class in the source code and construct the prompt words as follows:
[0113] In the following method, lines 2-4 are not covered by the test code. The method convertDate is called by the userBirthAdd method in the UserService class; the userBirthAdd method in the UserService class is called by the userAdd method in the UserAPI class. The userAdd method in the UserAPI class is the interface that is ultimately provided to the front end. Please give suggestions on which interface test scenarios should be added to improve the test code coverage so that it can cover the uncovered code lines:
[0114]
[0115]
[0116] The output of the large model is as follows:
[0117] To improve test coverage, especially to cover the untested code in lines 2-4, you can add the following test scenario:
[0118] 1. Test for empty string: Make sure that the method returns null when the input parameter is an empty string.
[0119] 2. Test for blank string: Already mentioned in point 1, make sure that the method returns null when the input parameter is a string containing only spaces.
[0120] 3. Test null value: Enter null value and make sure StringUtils.isBlank can handle it correctly and return null.
[0121] Step 308: Update the test script based on the interface test scenario to be added.
[0122] In this application, the test script can be updated according to the added interface test scenario, so as to use the updated test script for testing and improve the coverage.
[0123] In an embodiment of the present application, the uncovered code fragments can be analyzed from the call chain, and the codes of each layer of the call chain can be extracted. Based on the codes of each layer of the call chain, a large model can be used to determine the interface test scenarios to be added, so that the interface test scenarios to be added can be used to update the test scripts and improve the coverage.
[0124] In one embodiment of the present application, based on the above embodiment, it is also possible to determine whether there are omissions in the test analysis according to the modules affected by the code change.
[0125] Exemplarily, the test cases written by the user can be attached to the corresponding system modules. Through analysis, it can be obtained which modules are covered by the test cases written by the current user, and the target test cases involved in the current code changes can be determined. Therefore, based on the target test cases, the modules corresponding to the target test cases can be determined. If the modules corresponding to the target test cases include the modules covered by the test cases written by the user, it can be determined that the user's test analysis is complete. If there are modules in the modules corresponding to the target test cases that are not covered by the test cases written by the user, it can be considered that the user's test analysis has omissions, and a prompt message can be generated to prompt the user that there are missing modules.
[0126] For example, the set of modules covered by the test cases currently written by the user is A, and the set of modules corresponding to the target test cases is B. If set B contains set A, it can be considered that the user's test analysis is complete. If there are elements in set B that are not in set A, it is considered that the user's test analysis is missing, and the user is prompted for possible missing modules.
[0127] Therefore, by comparing the modules corresponding to the target test cases found based on code changes and the modules covered by the test cases written by the user, it is possible to determine whether there are omissions in the test analysis, which can help users improve the test cases and thus improve the test coverage and accuracy.
[0128] In order to implement the above embodiments, the present application also proposes a testing device. Figure 4 A schematic diagram of the structure of a testing device provided in an embodiment of the present application.
[0129] like Figure 4 As shown, the testing device 400 includes:
[0130] A first acquisition module 410 is used to acquire code submission records;
[0131] A first determination module 420, configured to determine a code change file based on the code submission record;
[0132] A second determination module 430 is used to perform call relationship analysis on the code change file to determine the target interface affected by the code change; wherein the target interface refers to the externally exposed interface affected by the code change;
[0133] A search module 440 is used to search for a target test case associated with the target interface from existing test cases;
[0134] The testing module 450 is used to perform testing based on the target test case and obtain test results.
[0135] Further, in a possible implementation of the embodiment of the present application, the second determining module 430 is configured to:
[0136] Analyze the code change file to obtain a file structure table and a method call relationship table;
[0137] Determining, according to the file structure table, the element type affected by the code change;
[0138] In response to the element type being a method, the target interface is determined by querying the method call relationship table.
[0139] Furthermore, in a possible implementation of the embodiment of the present application, the search module 440 is used to:
[0140] Obtaining annotation information in the test script corresponding to the existing test case;
[0141] Extracting the corresponding relationship between the test case and the interface from the annotation information;
[0142] According to the target interface, the target test case is determined by querying the corresponding relationship.
[0143] Furthermore, in a possible implementation of the embodiment of the present application, the search module 440 is used to:
[0144] Determining target test steps involved in the target interface;
[0145] Get the title of the target test step;
[0146] The title is analyzed to determine the target test case.
[0147] Furthermore, in a possible implementation of the embodiment of the present application, the testing module 450 is used to:
[0148] In response to the number of the target test cases being greater than the number of currently idle execution machines, the target test cases are sorted in descending order of historical average execution times of the target test cases to obtain a test case list;
[0149] Traversing the test case list, selecting the target test cases one by one from the test case list, and adding them to the group with the shortest historical average execution time; wherein each idle execution machine is assigned a group, and each group corresponds to a test sub-plan;
[0150] Testing is performed by executing the test subplan.
[0151] Furthermore, in a possible implementation of the embodiment of the present application, the device may also include:
[0152] A second acquisition module is used for, in response to determining that there is a code fragment not covered by the test based on the test result, acquiring the code of each layer of the call chain based on the call chain of the uncovered code fragment;
[0153] The third acquisition module is used to acquire the interface test scenario to be added based on the code of each layer of the call chain and using the large model;
[0154] An update module is used to update the test script based on the interface test scenario to be added.
[0155] It should be noted that the above explanations of the test method embodiment are also applicable to the test device of this embodiment and will not be repeated here.
[0156] In the embodiment of the present application, the code change file is determined according to the code submission record, the target interface affected by the code change is determined by performing call relationship analysis on the code change file, and the target test case associated with the target interface is found from the existing test cases, and then the test is performed based on the target test case. Thus, based on the code submission record, the interface affected by the code change is identified, and based on the affected interface, a suitable test case is found from the existing test cases, which can ensure full coverage of the affected area, improve the accuracy of the test, and ensure the completeness and quality of the test scenario when the software complexity increases.
[0157] In order to implement the above embodiments, the present application also proposes an electronic device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method provided by the above embodiments.
[0158] In order to implement the above embodiments, the present application also proposes a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the methods provided by the above embodiments.
[0159] In order to implement the above embodiments, the present application also proposes a computer program product, including a computer program, which implements the methods provided by the above embodiments when executed by a processor.
[0160] The collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in this application are in compliance with relevant laws and regulations and do not violate public order and good morals.
[0161] It should be noted that personal information from users should be collected for legitimate and reasonable purposes and should not be shared or sold outside of these legitimate uses. In addition, such collection / sharing should be carried out after receiving the user's informed consent, including but not limited to notifying the user to read the user agreement / user notice and sign the agreement / authorization including authorization of relevant user information before the user uses the function. In addition, any necessary steps should be taken to protect and safeguard access to such personal information data and ensure that others who have access to personal information data comply with its privacy policy and procedures.
[0162] The present application is expected to provide an implementation scheme for users to selectively block the use or access of personal information data. That is, the present disclosure is expected to provide hardware and / or software to prevent or block access to such personal information data. Once the personal information data is no longer needed, the risk can be minimized by limiting data collection and deleting the data. In addition, when applicable, such personal information is de-identified to protect the privacy of the user.
[0163] In the description of the aforementioned embodiments, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0164] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of this application, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0165] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0166] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0167] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0168] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0169] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0170] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present application. < / commit-hash-last>
Claims
1. A testing method, characterized in that: The following steps are involved: Get code submission records; Determine a code change file based on the code submission record; Performing call relationship analysis on the code change file to determine the target interface affected by the code change; wherein the target interface refers to the externally exposed interface affected by the code change; Searching for a target test case associated with the target interface from existing test cases; Perform a test based on the target test case and obtain a test result.
2. The method according to claim 1, characterized in that The performing call relationship analysis on the code change file to determine the target interface affected by the code change includes: Analyze the code change file to obtain a file structure table and a method call relationship table; Determining, according to the file structure table, the element type affected by the code change; In response to the element type being a method, the target interface is determined by querying the method call relationship table.
3. The method according to claim 1, characterized in that The step of searching for a target test case associated with the target interface from existing test cases includes: Obtaining annotation information in the test script corresponding to the existing test case; Extracting the corresponding relationship between the test case and the interface from the annotation information; According to the target interface, the target test case is determined by querying the corresponding relationship.
4. The method according to claim 1, characterized in that The step of searching for a target test case associated with the target interface from existing test cases includes: Determining target test steps involved in the target interface; Get the title of the target test step; The title is analyzed to determine the target test case.
5. The method according to claim 1, characterized in that The testing based on the target test case includes: In response to the number of the target test cases being greater than the number of currently idle execution machines, the target test cases are sorted in descending order of historical average execution times of the target test cases to obtain a test case list; Traversing the test case list, selecting the target test cases one by one from the test case list, and adding them to the group with the shortest historical average execution time; wherein each idle execution machine is assigned a group, and each group corresponds to a test sub-plan; Testing is performed by executing the test subplan.
6. The method according to any one of claims 1 to 5, characterized in that Also includes: In response to determining that there is a code fragment not covered by the test based on the test result, obtaining codes of each layer of the call chain based on the call chain of the code fragment not covered; Based on the code of each layer of the call chain, the interface test scenario to be added is obtained by using the large model; Update the test script based on the interface test scenario to be added.
7. A testing device, characterized in that: include: The first acquisition module is used to acquire code submission records; A first determination module, configured to determine a code change file based on the code submission record; A second determination module is used to perform call relationship analysis on the code change file to determine the target interface affected by the code change; wherein the target interface refers to the externally exposed interface affected by the code change; A search module, used to search for a target test case associated with the target interface from existing test cases; The test module is used to perform a test based on the target test case and obtain a test result.
8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.
Citation Information
Cited By
Automatic testing method and system based on retrieval enhancement generation and large language model
CN120295907A
Test case detection method and device, storage medium and electronic equipment
CN120429241A
Test case detection method and device, storage medium and electronic equipment
CN120429241B