Test case selection method and device, equipment and storage medium
By obtaining the change part of the old version of the code and the static call link in the software test, and selecting test cases involving the static call link of the function before the change, the problem of inability to effectively regress the test based on code coverage in the existing technology is solved, and the implementation of the problem of the inability to effectively regress the test based on the code coverage rate is achieved. A more comprehensive new version of code testing.
Patent Information
- Application Number
- CN202411517384.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-01-10
AI Technical Summary
In software testing in the prior art, test cases selected based on code coverage cannot effectively conduct regression testing of new version codes and cannot fully cover the impact of code changes.
By obtaining the changed part of the code of the old version of the object being tested, comparing and determining the function that belongs to before the change, looking for a static call link containing at least two call relationships between functions from the pre-stored static call link, and selecting these links involved The call interface information of the road is used as a test case.
Through static analysis, the static call link that may be affected by code changes can be determined. The selected test cases can better cover the regression test of the new version of code and improve the test effect.
Smart Images

Figure CN119292943A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software testing technology, and in particular to a test case selection method, device, equipment and storage medium. Background Art
[0002] In the field of software testing, when the old version of the code of the object under test is changed, regression testing is required on the new version of the code to verify that the function and / or performance of the object under test after the code change meets the expected requirements.
[0003] Currently, regression testing is usually performed by selecting test cases that produce higher code coverage when testing old version codes. The defect of this test case selection method is that it only considers the code coverage of old version codes and cannot achieve the effect of regression testing on new version codes. Summary of the invention
[0004] The embodiments of the present application provide a method, apparatus, device and storage medium for selecting test cases, which are used to solve the problem that when regression testing is required for the code change of the object under test, the test cases selected based on code coverage cannot effectively achieve regression testing for the new version of the code.
[0005] The present application embodiment adopts the following technical solutions: A method for selecting a test case, comprising: Obtain the changed code of the old version of the object under test; Compare the changed portion of code with the old version of code to determine the function to which the changed portion of code belongs before the change; Searching for a static call link to which the function belongs from pre-stored static call links; each static call link includes a call relationship between at least two functions in the old version code obtained by statically analyzing the old version code; The test cases involving the calling interface information of the static calling link are taken as the selected test cases.
[0006] A test case selection device, comprising: A changed code acquisition unit, used for acquiring a changed portion of code that is changed from an old version of the code of the object under test; a function-belonging determination unit, which compares the changed portion of code with the old version of code to determine the function to which the changed portion of code belongs before the change; A static call link search unit is used to search for a static call link to which the function belongs from pre-stored static call links; each static call link contains a call relationship between at least two functions in the old version code obtained by statically analyzing the old version code.
[0007] A computing device, comprising: a memory and a processor, wherein: The memory is used to store computer programs; The processor is coupled to the memory and is used to execute the computer program stored in the memory to perform the above method.
[0008] A computer-readable storage medium storing a computer program, wherein the computer program can implement the above method when executed by a computer.
[0009] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects: Since the static call link is obtained through static analysis of the old version of the code (understanding and recording the calling relationship between functions by parsing the source code structure without executing the code), the static call link contains the calling information of the function to which the changed part of the code belonged before the change. By finding the static call link that contains the function to which the changed part of the code belonged before the change, the static call link that may be affected by the code change can be determined. Therefore, the test case involving the calling interface information of the found static call link is used as the selected test case, which can better achieve the effect of regression testing on the new version of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 A specific implementation flow chart of a method for selecting a test case provided in an embodiment of the present application; Figure 2 A schematic diagram of an implementation flow of a specific implementation method in a method for selecting a test case provided in an embodiment of the present application; Figure 3 A schematic diagram of the specific structure of a test sample selection device provided in an embodiment of the present application; Figure 4 A schematic diagram of the specific structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0011] In order to more clearly explain the embodiments of the present application, the following terms are first explained: Regression testing: refers to retesting after modifying the old code of the software to confirm that the modification has not introduced new errors or caused errors in other codes. Regression testing is an integral part of the software life cycle, and multiple regression tests may be performed at various stages of software development.
[0012] Code coverage: It is a metric in software testing that is used to evaluate the coverage of the source code of the object being tested by the test cases. It measures the proportion of the source code that is tested (or executed) when the test cases are executed.
[0013] Test case: refers to the description of the test task for a specific software product, reflecting the test plan, method, technology and strategy. In layman's terms, a test case is a set of test inputs, execution conditions and expected results compiled for a specific goal, and the user verifies whether the software source code meets a specific requirement.
[0014] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0015] Those skilled in the art may appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0016] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0017] In order to solve the problem that when regression testing is required for the code change of the object under test, the test cases selected based on code coverage cannot achieve the regression testing for the new version of the code well, an embodiment of the present application provides a method for selecting test cases.
[0018] The executor of the method may be any computing device that can implement the method, such as a server, a mobile phone, a personal computer, a smart wearable device, a smart robot, and the like.
[0019] In addition, the execution order of different steps is not limited in the embodiment of the present application. When using the method provided in the embodiment of the present application, the execution order of different steps can be adjusted according to actual needs.
[0020] For ease of description, the method provided in the embodiment of the present application is described in detail below by taking a test case selection device as the execution subject of the method as an example.
[0021] like Figure 1 As shown, it is a specific implementation flow chart of a test case selection method provided in an embodiment of the present application, including the following steps 11 to 14: Step 11, obtaining the changed part of the code of the old version of the object under test.
[0022] The object under test usually refers to the software or system under test, specifically, the software whose source code has been changed.
[0023] Changing part of the code means changing part of the code of the old version of the object under test (the old version of the source code). The code may be changed for: fixing vulnerabilities in the old version of the code, improving performance, improving user experience, etc.
[0024] Code changes include modifying or deleting part of the old version of the code, and adding new code based on the old version of the code.
[0025] Step 12: compare the changed portion of code with the old version of code to determine the function to which the changed portion of code belongs before the change.
[0026] A function is a function or method in a programming language. It is a named, executable block of code that encapsulates a specific function or behavior and can receive input through parameters and output results through return values.
[0027] The function to which the changed portion of code belongs before the change refers to the function to which the portion of code corresponding to the changed portion of code in the old version of the code belongs.
[0028] Among them, the corresponding code: if the code change is modification, the corresponding code is the part of the code in the old version code before modification; if the code change is deletion, the corresponding code is the part of the code in the old version code before deletion; if the code change is addition, the corresponding code is the part of the code in the old version code that is adjacent to the newly added code or the code that has a calling relationship with the newly added code.
[0029] Step 13: Search the static call link to which the function belongs from the pre-stored static call links.
[0030] The call link in the embodiment of the present application refers to the call link of the function, specifically, a link formed by the call relationship between functions. In the program, functions are basic execution units, and they can call each other to complete specific tasks.
[0031] Each static call link includes a call relationship between at least two functions in the old version code obtained by statically analyzing the old version code.
[0032] Static analysis refers to tracing the calling relationship of functions by analyzing the source code of the program (in this embodiment, the old version code). Static analysis does not require the execution of the program, but rather parses the program text to identify the various functions in the program statements and the calling relationship between functions.
[0033] In this embodiment, static analysis is performed on the old version code of the object under test to determine each static call link contained in the old version code, and each static call link is pre-stored.
[0034] A static call link including the function determined in step 12 is searched from pre-stored static call links as the static call link to which the function determined in step 12 belongs.
[0035] Step 14: select the test case involving the call interface information of the static call link as the selected test case; the test case is a test case that has been tested on the old version code.
[0036] The call interface is used to realize the communication and interaction between different programs or systems. It allows data and functions to be transferred from one program to another, realizing the expansion of the system and the enhancement of functions. Usually, a software system (the object under test in this embodiment) can be divided into multiple modules or components, each of which is responsible for a specific function. The call interface allows these modules to communicate through defined and / or public functions.
[0037] The calling interface information of the static calling link includes the entry function and input parameter information of the external calling interface of the static calling link. Among them, the external calling interface refers to the calling interface of the static calling link at the interface layer.
[0038] Since the static call link found in step 13 is related to the changed code, the test cases involving the call interface information of the static call link are selected as test cases, and test cases related to the changed code can be obtained. These test cases are used for regression testing, which can accurately test the impact of the changed code on the original code, software performance, or function.
[0039] In an implementation of this embodiment, in order to more comprehensively select test cases for regression testing, this implementation further includes the following steps 131-132: Step 131: Search the dynamic call link to which the function belongs from the pre-stored dynamic call links.
[0040] The dynamic call link refers to a series of paths that dynamically determine which functions to call based on certain conditions or input parameters during program execution. These paths are not completely determined when the program is compiled, but are selected and constructed based on specific situations during runtime.
[0041] In this implementation, the dynamic call link is determined by executing a test of the old version code based on the call relationship of the functions in the old version code during operation.
[0042] Step 132: Select test cases for regression testing based on the code coverage of the dynamic call link by the test cases.
[0043] The code coverage of the call link by the test case is determined in the following way: When executing a test case, the test case identifier pre-added to the request header for calling the object under test is captured through a probe integrated into the code of the object under test; based on the captured test case identifier and the call link information corresponding to the request for calling the object under test, the code coverage of the call link by the test case is determined.
[0044] The test cases executed above may be all test cases. Before executing the test cases, a test case identifier (a unique test case ID) is added to the HTTP request header of the object under test, and a probe is integrated into the code of the object under test. The probe is used to capture the test case identifier when executing the test case.
[0045] The call link information corresponding to the request to call the object under test refers to the call relationship between functions in the old version code that is run in response to the request to call the object under test issued by the test case when the test case is executed.
[0046] The code coverage of each test case can be obtained in the above way.
[0047] The test cases involving the call interface information of the static call link obtained in the above step 14 and the test cases selected based on the code coverage of the dynamic call link by the test cases in step 131 are used together as test cases for regression testing.
[0048] That is to say, the test cases selected based on the dynamic call link and the test cases selected based on the static call link are used together as the test cases for regression testing, which includes the call links not involved in the static call link, making the test cases selected for regression testing more comprehensive.
[0049] For the function determined in step 12, in order to make the queried call link more comprehensive when querying the call link to which the function belongs in step 13, before the query operation in step 13, the pre-stored static call link and the pre-registered dynamic call link are stored as the full call link, so that after determining the function to which the changed part of the code belongs before the change, the call link to which the function belongs can be searched in the full call link.
[0050] Among them, the formation of the full call link can be: respectively obtain the pre-stored static call link and dynamic call link, and add the dynamic call link not covered by the static call link (that is, the link that cannot be obtained by static analysis but can be obtained after the code is run) to the static call link, so as to obtain the full call link.
[0051] like Figure 2 As shown, a schematic diagram of a specific implementation of the test case selection method of this embodiment is provided. Specifically, the following steps 21 to 27 are included: Step 21, obtaining the changed part of the code of the old version of the object under test.
[0052] Step 22: compare the changed portion of code with the old version of code to determine the function to which the changed portion of code belongs before the change.
[0053] The above steps 21 and 22 correspond to steps 11 and 12 respectively, and will not be described in detail.
[0054] Step 23: Search the pre-stored full call links for the call link to which the function determined in step 22 belongs. The determined call link may be a static call link and / or a dynamic call link.
[0055] Step 24, determining whether the call link determined in step 23 is a static call link; if so, executing step 25; if not, executing step 26.
[0056] Step 25: taking the test case involving the calling interface information of the static calling link as the selected test case.
[0057] Step 26, select a test case based on the code coverage of the dynamic call link by the test case.
[0058] Step 27, the test cases selected in step 25 and the test cases selected in step 26 are used together as test cases for regression testing.
[0059] In the above-mentioned embodiment of the present application, since the static call link is obtained by static analysis of the old version code (understanding and recording the calling relationship between functions by parsing the source code structure without executing the code), the static call link contains the calling information of the function to which the changed part of the code belonged before the change. By finding out the static call link containing the function to which the changed part of the code belonged before the change, the static call link that may be affected by the code change can be determined. Therefore, the test case involving the calling interface information of the found static call link is used as the selected test case, which can better cover the test of the changed part of the code.
[0060] In order to solve the problem that when regression testing is required for the code of the object under test, the test cases selected based on code coverage cannot effectively achieve regression testing for the new version of the code, based on the same inventive concept as the above-mentioned embodiments of the present application, embodiment 2 of the present application provides a test case selection device.
[0061] The specific structural diagram of the device is shown in Figure 3 As shown, it includes the following functional units 31-34: The changed code acquisition unit 31 is used to acquire the changed part of the code of the old version of the tested object.
[0062] The function determination unit 32 compares the changed portion of code with the old version of code to determine the function to which the changed portion of code belongs before the change.
[0063] The static call link search unit 33 is used to search the static call link to which the function belongs from the pre-stored static call links.
[0064] Each of the static call links includes a call relationship between at least two functions in the old version code obtained by statically analyzing the old version code; The test case selection unit 34 is used to select the test case involving the call interface information of the static call link as the selected test case. The test case is the test case that has been tested on the old version code.
[0065] The interface call information includes the entry function and input parameter information of the external call interface of the static call link.
[0066] In a feasible implementation, the selection device further includes a dynamic call link search unit, and the dynamic call link search unit is specifically used to: The dynamic call link to which the function belongs is searched from the pre-stored dynamic call links; the dynamic call link is determined by executing the test of the old version code based on the call relationship of the function in the old version code during the running process; and the test case is selected according to the code coverage of the dynamic call link by the test case.
[0067] The code coverage of the call link by the test case is determined in the following way: When executing a test case, the test case identifier pre-added to the request header for calling the object under test is captured through a probe integrated into the code of the object under test; based on the captured test case identifier and the call link information corresponding to the request for calling the object under test, the code coverage of the call link by the test case is determined.
[0068] Furthermore, in order to select more comprehensive test cases for regression testing, the selection device also includes: taking the test cases involving the calling interface information of the static calling link, and the test cases selected for regression testing based on the code coverage of the dynamic calling link by the test cases, as the selected test cases.
[0069] The selection device also includes: storing the pre-stored static call link and the pre-stored dynamic call link as a full call link; after determining the function to which the changed part of the code belongs before the change, searching the call link to which the function belongs from the full call link.
[0070] The test case selection device provided in the above embodiment of the present application, since the static call link is obtained by static analysis of the old version code (understanding and recording the calling relationship between functions by parsing the source code structure without executing the code), the static call link contains the calling information of the function to which the changed part of the code belonged before the change. By finding out the static call link containing the function to which the changed part of the code belonged before the change, the static call link that may be affected by the code change can be determined. Therefore, the test case involving the calling interface information of the found static call link is used as the selected test case, which can better achieve the effect of regression testing on the new version of the code.
[0071] Based on the same inventive concept as the aforementioned embodiments of the present application, the embodiments of the present application also provide a computing device.
[0072] like Figure 4As shown, the computing device includes: a memory 41 and a processor 42. The memory 41 can be configured to store various other data to support operations on the electronic device. Examples of these data include instructions for any application or method for operating on the electronic device. The memory 41 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk.
[0073] The processor 42 is coupled to the memory 41 and is used to execute the computer program stored in the memory 41 to execute the test sample selection method described in the above embodiment.
[0074] When the processor 42 executes the computer program for the method of selecting test samples, since the static call link is obtained by static analysis of the old version of the code (understanding and recording the calling relationship between functions by parsing the source code structure without executing the code), the static call link contains the calling information of the function to which the changed part of the code belonged before the change. By finding out the static call link containing the function to which the changed part of the code belonged before the change, the static call link that may be affected by the code change can be determined. Therefore, the test case involving the calling interface information of the found static call link is used as the selected test case, which can better achieve the effect of regression testing on the new version of the code.
[0075] When the processor 42 executes the computer program in the memory 41, in addition to the above functions, it can also realize other functions, and the details can be referred to the description of the previous embodiments.
[0076] Further, such as Figure 4 As shown, the computing device also includes: a display 44, a communication component 43, a power component 45, an audio component 46 and other components. Figure 4 Only some components are shown schematically, and it does not mean that the computing device only includes Figure 4 Components shown.
[0077] Accordingly, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, and when the computer program is executed by a computer, the methods provided in the above embodiments can be implemented.
[0078] An embodiment of the present application also provides a computer program product, including a computer program, which implements the methods provided in the above embodiments when executed by a processor.
[0079] The computer program product includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a processor, the methods provided in the above embodiments are implemented.
[0080] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0081] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0082] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these 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.
Claims
1. A method for selecting a test case, characterized in that: include: Obtain the changed code of the old version of the object under test; Compare the changed portion of code with the old version of code to determine the function to which the changed portion of code belongs before the change; Searching for a static call link to which the function belongs from pre-stored static call links; each static call link includes a call relationship between at least two functions in the old version code obtained by statically analyzing the old version code; The test cases involving the calling interface information of the static calling link are taken as the selected test cases.
2. The method according to claim 1, characterized in that The method further comprises: Searching for the dynamic call link to which the function belongs from each pre-stored dynamic call link; each dynamic call link is determined by executing a test of the old version code based on the call relationship of the function in the old version code during the running process; Test cases for regression testing are selected based on the code coverage of the dynamic call link by the test cases.
3. The method according to claim 2, characterized in that The code coverage of the call link by the test case is determined in the following way: When executing the test case, the probe integrated into the code of the object under test captures the test case identifier pre-added to the request header for calling the object under test; Based on the captured test case identifier and the call link information corresponding to the request to call the object under test, the code coverage of the call link by the test case is determined.
4. The method according to claim 2, characterized in that The method further comprises: The test cases involving the calling interface information of the static calling link and the test cases selected based on the code coverage of the dynamic calling link by the test cases are used together as the test cases for regression testing.
5. The method according to claim 2, characterized in that The method further comprises: Storing the pre-stored static call links and the pre-stored dynamic call links as full call links; After determining the function to which the changed portion of code belongs before the change, the call link to which the function belongs is searched from the full call link.
6. The method according to claim 1, characterized in that The calling interface information includes: The entry function and input parameter information of the external call interface of the static call link.
7. A test case selection device, characterized in that: include: A changed code acquisition unit, used for acquiring a changed portion of code that is changed from an old version of the code of the object under test; a function-belonging determination unit, which compares the changed portion of code with the old version of code to determine the function to which the changed portion of code belongs before the change; A static call link search unit, used to search for a static call link to which the function belongs from pre-stored static call links; each static call link includes a call relationship between at least two functions in the old version code obtained by statically analyzing the old version code; The test case selection unit is used to select the test case involving the call interface information of the static call link as the selected test case.
8. A computing device, characterized in that include: Memory and processor, wherein: The memory is used to store computer programs; The processor is coupled to the memory and is used to execute the computer program stored in the memory to execute the method described in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a computer, it can implement the method described in any one of claims 1 to 6.
10. A computer program product, characterized in that It includes a computer program, which, when executed by a processor, implements the method described in any one of claims 1 to 6.