Test case acquisition method and device, medium and electronic equipment
By obtaining the corresponding object function name of the function at the modified position in the source code to be tested, and obtaining the target test case based on the preset mapping relationship, the problems of large test strength and long development cycle in the existing technology are solved, and efficient test cases are achieved Acquire and shorten development cycles.
Patent Information
- Application Number
- CN202311018372.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-11
- Publication Date
- 2025-02-21
AI Technical Summary
During the software development process, it is difficult for the existing technology to accurately identify and test the functional modules modified by the source code, resulting in high testing intensity and long testing time, which in turn extends the development cycle.
By obtaining the target function name corresponding to the modified position in the source code to be tested, based on the preset mapping relationship, the target test case corresponding to the target function name is obtained from multiple test cases in the database, and only the source code of the modified position is modified is performed. test.
Reduces test intensity and test time, shortens development cycle, and improves the reliability and accuracy of test cases.
Smart Images

Figure CN119493723A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of testing technology, and in particular to a test case acquisition method, device, medium and electronic device. Background Art
[0002] In the process of software development, in order to correct or improve the functions of the software, the source code needs to be modified. In order to ensure the stability and accuracy of the developed software, the modified source code needs to be tested. Usually, test cases are selected to test the source code, which makes the test intensity greater. Summary of the invention
[0003] The present disclosure provides a test case acquisition method, device, medium and electronic device, aiming to solve the above-mentioned problems.
[0004] In order to achieve the above-mentioned purpose, the first aspect of the present disclosure provides a test case acquisition method, the method comprising: acquiring source code to be tested, wherein the source code to be tested is source code after modifying the original test source code; extracting a target function name corresponding to a function at a modified position in the source code to be tested; based on a preset mapping relationship, acquiring a target test case corresponding to the target function name from multiple test cases in a database, wherein the preset mapping relationship includes a correspondence between each function name and a corresponding test case, and the target test case is used to test the source code at the modified position in the source code to be tested.
[0005] Optionally, before extracting the function name corresponding to the function at the modified position in the source code to be tested as the target function name, the method further includes: determining the modified position in the source code to be tested according to the original test source code and the source code to be tested.
[0006] Optionally, determining the modification position in the source code to be tested based on the original test source code and the source code to be tested includes: using preset instructions to capture the modified line number in the source code to be tested by comparing the original test source code and the source code to be tested; and determining the modified line number as the modification position.
[0007] Optionally, there are multiple target test cases, each target test case corresponds to at least one target function name, and after obtaining the target test case corresponding to the target function name from multiple test cases in the database based on a preset mapping relationship, it also includes: obtaining the number of target test cases; if the number of target test cases is greater than the preset number, obtaining the priority of the target function name corresponding to each target test case, wherein the priority of the target function name is positively correlated with the number of times the target test case corresponding to the target function name is called; outputting a prompt message according to the target function name whose priority is greater than the preset priority, wherein the prompt message is used to prompt to modify the function corresponding to the target function name whose priority is greater than the preset priority.
[0008] Optionally, after outputting the prompt information according to the target function name whose priority is greater than the preset priority, it also includes: after modifying the function corresponding to the target function name whose priority is greater than the preset priority, repeatedly executing the steps of obtaining the target test case corresponding to the target function name from multiple test cases in a database based on the preset mapping relationship, obtaining the number of target test cases, obtaining the priority of the target function name corresponding to each target test case if the number of target test cases is greater than the preset number, and outputting the prompt information according to the target function name whose priority is greater than the preset priority, until the number of target test cases is less than or equal to the preset number.
[0009] Optionally, before obtaining the target test case corresponding to the target function name from multiple test cases in a database based on a preset mapping relationship, the method also includes: obtaining sample source code, wherein the sample source code includes at least a function corresponding to the target function name; testing the sample source code using multiple test cases through a preset tool to obtain a test report; extracting multiple function names from the test report; and establishing the preset mapping relationship based on the multiple function names and the multiple test cases.
[0010] Optionally, the preset tool includes a C++ code analysis tool or a Python code analysis tool.
[0011] A second aspect of the present disclosure provides a test case acquisition device, the device comprising: an acquisition module, used to acquire source code to be tested, wherein the source code to be tested is a source code after the original test source code is modified; an extraction module, used to extract a target function name corresponding to a function at a modified position in the source code to be tested; a mapping module, used to acquire a target test case corresponding to the target function name from multiple test cases in a database based on a preset mapping relationship, wherein the preset mapping relationship includes a correspondence between each function name and a corresponding test case, and the target test case is used to test the source code at the modified position in the source code to be tested.
[0012] A third aspect of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect.
[0013] A fourth aspect of the present disclosure provides an electronic device, comprising: a memory on which a computer program is stored; and a processor for executing the computer program in the memory to implement the steps of the method described in the first aspect.
[0014] The present invention provides a test case acquisition method, device, medium and electronic device. The source code to be tested is a source code modified on the basis of the original test source code. When the source code to be tested needs to be tested, only the modified part needs to be tested. Therefore, the target function name corresponding to the function at the modified position in the source code to be tested is obtained, and based on a preset mapping relationship, the target test case corresponding to the target function name is determined from multiple test cases in a database. The target test case obtained according to the target function name corresponding to the modified position is used to test the source code corresponding to the modified position. There is no need to test the entire source code to be tested, which can reduce the test intensity, shorten the test time, and thus shorten the development cycle.
[0015] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure but do not constitute a limitation of the present disclosure. In the accompanying drawings:
[0017] Figure 1 is a schematic diagram of an application environment of the test case acquisition method shown in the present disclosure;
[0018] Figure 2 is a flowchart of a test case acquisition method shown in an exemplary embodiment of the present disclosure;
[0019] Figure 3 is a flowchart of a test case acquisition method shown in another exemplary embodiment of the present disclosure;
[0020] Figure 4 is a flowchart of a test case acquisition method shown in another exemplary embodiment of the present disclosure;
[0021] Figure 5 is a flowchart of a test case acquisition method shown in another exemplary embodiment of the present disclosure;
[0022] Figure 6 is a block diagram of a test case acquisition device according to an exemplary embodiment;
[0023] Figure 7 The invention is a block diagram of an electronic device for a test case acquisition method according to an exemplary embodiment. DETAILED DESCRIPTION
[0024] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0025] In the process of software development, in order to correct or improve the functions of the software, the source code needs to be modified. In order to ensure the stability and accuracy of the developed software, the modified source code needs to be tested again. At present, since it is impossible to accurately identify the functional modules affected by the modification and change of the source code, the test cases used to test the source code are usually used again to test the modified source code. For example, the number of test cases for testing the source code is 500. After the source code is modified, the source code is still tested with these 500 test cases. However, in the modified source code, the unmodified part has been tested in the source code testing phase. In fact, only the modified part needs to be tested, and the modified part may only need 50 test cases. Therefore, when all test cases are used for testing, the unmodified part is included, so that a large number of irrelevant test cases are executed, which increases the test intensity and wastes test resources, resulting in a longer test time for the modified source code, low test efficiency, and a long software development cycle.
[0026] Moreover, in the existing methods, test cases are usually selected manually. Different people may select different test cases, which makes the reliability of the test cases unstable, resulting in inaccurate test case selection and failure to achieve test results. This may cause some key functional modules to not be tested, resulting in insufficient test coverage of the source code and missed tests, leading to poor quality of the software that is finally launched.
[0027] To solve the above problems, the present disclosure provides a test case acquisition method, device, medium and electronic device. For the modified part of the source code to be tested, the test case is selected, which can reduce the test intensity, save test resources, and thus shorten the test cycle and development cycle. In addition, by presetting the mapping relationship, the target test case is automatically acquired, the target test case can be quickly obtained, the screening time of the test case is reduced, and the rationality and stability of the test case acquired each time can also be ensured. Among them, the test case acquisition method will be described in detail later.
[0028] The following will first introduce the application environment diagram involved in the method for obtaining test cases in this application. Figure 1 , the application environment includes a programming terminal 110, a server 120 and a test terminal 130. The programming terminal 110 is connected to the server 120 through a network, and the test terminal 130 is connected to the server 120 through a network. Optionally, the programming terminal 110 is a device such as a desktop computer or a laptop computer with a source code writing function. The server 120 can be an independent physical server, a server cluster composed of multiple physical servers, or a cloud server. The test terminal 130 is a device such as a desktop computer, a laptop computer, a smart phone, etc. with a software testing function.
[0029] The developer uses the programming terminal 110 to write source code, and uploads the source code to the server 120 for storage through the programming terminal 110. The server 120 stores various versions of source code, including source code to be tested. In addition, the server 120 also stores multiple test cases.
[0030] When screening the test cases for testing, the server 120 may determine the target test case from the multiple test cases according to the source code to be tested.
[0031] Alternatively, the test end 130 downloads the source code to be tested from the server 120, and sends a test request for testing the source code to be tested to the server 120. In response to the test request, the server 120 determines a target test case corresponding to the source code to be tested from multiple test cases, and sends the target test case to the test end 130.
[0032] Alternatively, the test end 130 downloads the source code to be tested and multiple test cases from the server 120. The test end 130 determines the target test case from the multiple test cases according to the source code to be tested.
[0033] Alternatively, after programming the source code, the programming terminal 110 saves it in a local folder of the programming terminal 110. The programming terminal 110 sends a test request to the server 120. In response to the test request, the server 120 determines a target test case corresponding to the source code to be tested from a plurality of test cases, and sends the target test case to the programming terminal 110.
[0034] Alternatively, after programming the source code, the programming terminal 110 saves it in a local folder of the programming terminal 110. The programming terminal 110 sends a test request to the server 120. In response to the test request, the server 120 sends multiple test cases to the programming terminal 110. The programming terminal 110 determines a target test case from the multiple test cases according to the source code to be tested.
[0035] It should be noted that when using the target test case for dynamic testing, a new version of software corresponding to the source code to be tested needs to be installed on the programming end 110 or the testing end 130. When using the target test case for static testing, there is no need to install a new version of software.
[0036] See also Figure 2 , Figure 2 is a flow chart of a test case acquisition method shown in an exemplary embodiment of the present disclosure, and the test case acquisition method can be applied to Figure 1 The application scenarios shown, Figure 1 The programming end 110, the server 120, the test end 130, Figure 6 The test case acquisition device 200 shown, Figure 7 The electronic device 700 shown, Figure 7 The processor 701 and the computer readable storage medium in this embodiment are used as an example of an electronic device, where the electronic device can be a programming terminal 110, a server 120 or a test terminal 130. Figure 2 The process shown is described in detail, and the test case acquisition method may specifically include the following steps:
[0037] Step S110: Obtain source code to be tested, wherein the source code to be tested is a source code obtained by modifying the original test source code.
[0038] In order to fix some problems in the software or add some new functions to the software, the software needs to be upgraded. During this process, the developer needs to modify the source code corresponding to the software. The original test source code can be the source code corresponding to the previous version of the software. The developer modifies the original test source code to obtain the source code to be tested. The source code to be tested can be understood as the source code corresponding to the new version of the software or the source code corresponding to the test version of the software.
[0039] Alternatively, the original test source code and the source code to be tested may both be source codes corresponding to different development stages of the same software development. For example, in the process of developing a new version of software, after the source code is tested using test cases to obtain test results, the source code is modified based on the test results, or new functions are added to the source code according to project requirements. In this case, the source code of the most recent test is used as the original test source code, and modifications are made based on the original test code to obtain the source code to be tested.
[0040] In one embodiment, the version control system (Subversion, SVN) is a centralized source code management tool that can be used to manage source code, which records the source code of each version of the project. When the developer needs to modify or write the original test source code, the developer downloads the original test source code from SVN, modifies and writes it, and obtains the source code to be tested. The developer then uploads the source code to be tested to SVN for storage. When the source code to be tested needs to be tested, the source code to be tested is downloaded from SVN.
[0041] In another embodiment, the electronic device locally stores the original test source code, and the developer modifies and writes the original test source code locally on the electronic device to obtain the source code to be tested.
[0042] Step S120: extract the target function name corresponding to the function at the modification position in the source code to be tested.
[0043] The original test source code has been tested during the development and programming phase of the original test source code. Modifications are made to the original test source code to obtain the source code to be tested. When testing the source code to be tested, the unmodified position in the source code to be tested has been tested in the original test source code results. In order to shorten the test time, only the source code at the modified position in the source code to be tested needs to be tested. Extract the target function name corresponding to the function at the modified position in the source code to be tested, that is, extract the target function name corresponding to the function contained in the source code at the modified position, so as to facilitate the subsequent selection of test cases according to the target function name.
[0044] For example, the target function name can be IF, SUM, LOOKUP, etc.
[0045] In one implementation, the modification position in the source code to be tested is determined by a preset instruction, and then a script is used to extract the target function name of the function corresponding to the modification position.
[0046] In another embodiment, a search tool is installed on the electronic device, and the two versions of the original test source code and the source code to be tested are imported into the search tool. After the search tool searches, the modified position in the source code to be tested is determined, and the modified position is marked. Optionally, the search tool can be WinMergePortable software. Then, a script is used to extract the target function name of the function corresponding to the modified position.
[0047] Step S130: Based on a preset mapping relationship, obtain a target test case corresponding to the target function name from multiple test cases in the database, wherein the preset mapping relationship includes a correspondence between each function name and the corresponding test case, and the target test case is used to test the source code at the modified position in the source code to be tested.
[0048] A plurality of test cases are stored in the database, and the plurality of test cases include a target test case. A preset mapping relationship is pre-established, and the preset mapping relationship includes a plurality of pairs of corresponding relationships including a corresponding relationship between a target function name and a target test case. For example, the preset mapping relationship may be in the form of a comparison table. The preset mapping relationship may also be stored in the database.
[0049] It should be noted that in the preset mapping relationship, there may be a one-to-one correspondence between the function name and the test case, that is, one function name corresponds to one test case. There may not be a one-to-one correspondence between the function name and the test case, that is, one test case corresponds to multiple functions, which can be understood as one test case can test multiple functions. Alternatively, a function name can correspond to multiple test cases, which can be understood as the function corresponding to the function name can be tested with multiple test cases. In this case, if the number of target test cases corresponding to the target function name is multiple, and the multiple target test cases are all testing the same function, if the multiple target test cases are output at the same time and used to test the source code of the modified position at the same time, the source code of the modified position will be repeatedly tested, wasting test resources. Therefore, only one of the multiple target test cases can be output, as long as the output target test case can test the source code of the modified position.
[0050] Based on the preset mapping relationship, the target test case corresponding to the target function name is determined, and the target test case is called from multiple test cases in the database. The target test case obtained according to the function name corresponding to the function at the modified position is used to test the source code at the modified position. It can be understood that only the modified part of the source code to be tested is tested, and the unmodified part of the source code does not need to be tested repeatedly.
[0051] The test case acquisition method provided in the present embodiment acquires source code to be tested, where the source code to be tested is source code after the original test source code is modified; extracts the target function name corresponding to the function at the modified position in the source code to be tested; based on a preset mapping relationship, acquires a target test case corresponding to the target function name from multiple test cases in a database, wherein the preset mapping relationship includes a correspondence between multiple function names and a test case corresponding to each of the multiple function names, and the obtained target test case is used to test part of the source code in the source code to be tested, without testing the entire source code to be tested, which can reduce the test intensity, shorten the test time, and thus shorten the development cycle.
[0052] Based on the above embodiment, this embodiment proposes a test case acquisition method, see Figure 3 , the test case acquisition method comprises the following steps:
[0053] Step S210: Obtain source code to be tested, wherein the source code to be tested is a source code obtained by modifying the original test source code.
[0054] The specific description of step S210 can refer to the above step S110, which will not be repeated here.
[0055] Step S220: Determine a modification position in the source code to be tested according to the original test source code and the source code to be tested.
[0056] The original test source code and the source code to be tested are compared, and the positions in the source code to be tested that are different from the original test source code are modification positions. Through the comparison, the modification positions in the source code to be tested are determined.
[0057] In one implementation, by using preset instructions, by comparing the original test source code with the source code to be tested, the modified line number in the source code to be tested is captured, for example, the modified line number may be line 42 to line 78, line 38, etc. The modified line number is determined as the modification position.
[0058] In another embodiment, a change report is generated by comparing the original test source code with the source code to be tested using a preset instruction, wherein the change report is used to record the difference between the original test source code and the source code to be tested, and the change report may include the change position (e.g., line number), change content, change time, etc. The electronic device may directly read the modification position from the change report.
[0059] For example, the preset instruction may be a fix command (fc) command.
[0060] Step S230: extract the target function name corresponding to the function at the modification position in the source code to be tested.
[0061] Step S240: Based on a preset mapping relationship, obtain a target test case corresponding to the target function name from multiple test cases in the database, wherein the preset mapping relationship includes a correspondence between each function name and the corresponding test case, and the target test case is used to test the source code to be tested.
[0062] The specific description of steps S230 to S240 can refer to the above-mentioned steps S120 to S130, which will not be repeated here.
[0063] In the test case acquisition method provided in the present embodiment, the source code to be tested is the source code modified on the basis of the original test source code. When the source code to be tested needs to be tested, only the modified part needs to be tested. Therefore, the modification position in the source code to be tested is determined, and then the target test case is selected based on the target function name corresponding to the function at the modification position. The source code at the modification position in the source code to be tested is tested with the target test case, which can reduce the test intensity, shorten the test time, and thus shorten the development cycle.
[0064] In some scenarios, there are multiple target test cases, and each of the multiple target test cases corresponds to at least one target function name. Based on the above embodiment, the present disclosure provides a test case acquisition method, please refer to Figure 4 , the test case acquisition method comprises the following steps:
[0065] Step S310: Obtain source code to be tested, wherein the source code to be tested is a source code obtained by modifying the original test source code.
[0066] Step S320: extract the target function name corresponding to the function at the modification position in the source code to be tested.
[0067] Step S330, based on a preset mapping relationship, obtain a target test case corresponding to the target function name from multiple test cases in the database, wherein the preset mapping relationship includes a correspondence between each function name and the corresponding test case, and the target test case is used to test the source code at the modified position in the source code to be tested.
[0068] The specific description of steps S310 to S330 may refer to the above-mentioned steps S110 to S130 and will not be repeated here.
[0069] Step S340: Obtain the number of the target test cases.
[0070] For example, the number of target test cases is 80, 90, and so on.
[0071] Step S350: If the number of the target test cases is greater than the preset number, obtain the priority of the target function name corresponding to each target test case in the multiple target test cases, wherein the priority of the target function name is positively correlated with the number of times the target test case corresponding to the target function name is called.
[0072] For example, the preset number may be 50. When the number of target test cases is 80, the number of target test cases is greater than the preset number, and the priority of the target function name is obtained.
[0073] If the number of target test cases is not greater than the preset number, that is, the number of target test cases is less than or equal to the preset number, it means that the number of target test cases screened out is reasonable, and the test can be completed quickly through the target test cases. For example, if the preset number is 50, when the number of target test cases is 48, the number of target test cases is not greater than the preset number, and the target test cases are used for testing.
[0074] The priority of the target function name is positively correlated with the number of times the target test case corresponding to the target function name is called. If the priority of the target function name is higher, the target test case corresponding to the target function name is called more times, which means that the function corresponding to the target function name may be a public function. Public functions may be widely called and involve many functions. If a public function is tested, it may involve testing other functions associated with the public function. Therefore, the number of target test cases screened out may be large, making the test workload high. Conversely, if the priority of the target function name is lower, the target test case corresponding to the target function name is called less times.
[0075] Exemplarily, the number of times multiple test cases in the database are called is counted, and the priority of the function name is divided according to the number of times the test case corresponding to the function name is called. For example, if the number of calls is within the first preset range, the corresponding priority is the first priority; if the number of calls is within the second preset range, the corresponding priority is the second priority; if the number of calls is within the third preset range, the corresponding priority is the third priority. The lower limit of the first preset range is the upper limit of the second preset range, the lower limit of the second preset range is the upper limit of the third preset range, the first priority is greater than the second priority, and the second priority is greater than the third priority.
[0076] Step S360: output prompt information according to the target function name whose priority is greater than the preset priority, wherein the prompt information is used to prompt to modify the function corresponding to the target function name whose priority is greater than the preset priority.
[0077] Based on the above analysis, the function corresponding to the target function name with a priority greater than the preset priority may be a public function. According to the target function name, a prompt message is output to prompt the developer to modify the function corresponding to the target function name.
[0078] Optionally, the prompt information is not limited to prompting to modify the function corresponding to the target function name, but can also prompt to modify other locations in the source code of the modification location. For example, in the prompt information, the reminder for the function corresponding to the target function name is placed at the front, and the modification reminders for other functions are placed at the back.
[0079] The prompt information can be output on the display screen of the electronic device to achieve the purpose of reminding the developer. The developer makes modifications again based on the prompt information, and readjusts the structure of the source code at the modified location based on the open-closed principle, design pattern, dependency injection, inversion of control, etc. The modification can include encapsulating, replacing, deleting, etc. the function corresponding to the target function name. After the modification, it can be avoided to pass through the aforementioned function again, and when obtaining the test case based on the preset mapping relationship, it can be avoided to call the aforementioned target test case again, so as to achieve the purpose of streamlining the test case set and shorten the test time.
[0080] After the developer modifies the function corresponding to the target function name according to the prompt information, steps S330 to S360 are repeated until the number of selected target test cases is less than or equal to the preset number, and then the target test cases are used to test the source code to be tested to shorten the test time.
[0081] If it takes time t1 to test the target test case obtained in step S330. It takes time t2 to test the target test case that meets the conditions obtained after the developer modifies the code according to the prompt information, and the condition here refers to that the number of target test cases is less than or equal to the preset number. After the above modification, the test time is reduced by the difference between t1 and t2, and the difference can be understood as the shortened test time. And the difference is greater than the time spent by the developer in modifying the function corresponding to the target function name. Therefore, from the overall point of view, this embodiment outputs prompt information to remind developers to adjust, which also plays a role in shortening the project development cycle.
[0082] Before the preset mapping relationship is used in the above embodiment, the preset mapping relationship should be created in advance. Optionally, before the step of obtaining the target test case corresponding to the target function name from multiple test cases in the database based on the preset mapping relationship, the test case acquisition method further includes:
[0083] Obtain sample source code, wherein the sample source code includes at least a function corresponding to the target function name, and optionally, the sample source code may be the original test source code or other source code of the same project. Test the sample source code using a plurality of test cases through a preset tool to obtain a test report. Optionally, the present disclosure may support C++ code and Python code, so the preset tool includes a C++ code analysis tool or a Python code analysis tool. For example, the C++ code analysis tool may be OpenCppCoverage, and the Python code analysis tool may be Coverage.py. Extract multiple function names from the test report. Establish the preset mapping relationship based on the multiple function names and the multiple test cases.
[0084] In one embodiment, see Figure 5 , test the sample source code using black box testing or automated testing, perform static analysis on the sample source code using a preset tool, and obtain a test report, which can be a hypertext markup language (HTML) report. The HTML report can include the number of lines of code, the number of lines where the function is located, the function name, the test case used by the function, etc. Extract the function name from the HTML report, and obtain the test case used by the function corresponding to the function name. Establish a corresponding relationship between the function name and the test case, and obtain a preset mapping relationship. Save the preset mapping relationship in a database.
[0085] The preset mapping relationship can be stored in the database. It should be noted that after the preset mapping relationship is created, it can be repeatedly used, and there is no need to create the preset mapping relationship once before each mapping.
[0086] In order to implement the embodiment of the above formula annotation method, this embodiment provides a test case acquisition device, Figure 6 A block diagram of a test case acquisition device provided by an embodiment of the present disclosure is shown. Figure 6 , the test case acquisition device 200 includes: an acquisition module 210, an extraction module 220 and a mapping module 230;
[0087] The acquisition module 210 is used to acquire the source code to be tested, wherein the source code to be tested is a source code obtained by modifying the original test source code;
[0088] An extraction module 220 is used to extract the target function name corresponding to the function at the modification position in the source code to be tested;
[0089] A mapping module 230 is used to obtain a target test case corresponding to the target function name from multiple test cases in a database based on a preset mapping relationship, wherein the preset mapping relationship includes a correspondence between each function name and a corresponding test case, and the target test case is used to test the source code at the modified position in the source code to be tested.
[0090] Optionally, the test case acquisition device 200 further includes: a modification position determination module;
[0091] The modification position determination module is used to determine the modification position in the source code to be tested according to the original test source code and the source code to be tested.
[0092] Optionally, modifying the position determination module includes: a grasping module and a position determination module;
[0093] A capture module, used for capturing the modified line numbers in the source code to be tested by comparing the original test source code with the source code to be tested using preset instructions;
[0094] The position determination module is used to determine the modified line number as the modified position.
[0095] Optionally, there are multiple target test cases, each target test case corresponds to at least one target function name, and the test case acquisition device 200 further includes: a number acquisition module, a priority acquisition module, and a prompt output module;
[0096] A number acquisition module, used to obtain the number of the target test cases;
[0097] A priority acquisition module, used for acquiring the priority of the target function name corresponding to each target test case if the number of the target test cases is greater than a preset number, wherein the priority of the target function name is positively correlated with the number of times the target test case corresponding to the target function name is called;
[0098] The prompt output module is used to output prompt information according to the target function name whose priority is greater than the preset priority, wherein the prompt information is used to prompt to modify the function corresponding to the target function name whose priority is greater than the preset priority.
[0099] Optionally, the test case acquisition device 200 further includes: a repeated execution module;
[0100] A repeated execution module is used to repeatedly execute the steps of obtaining the target test case corresponding to the target function name whose priority is greater than the preset priority from multiple test cases in a database based on a preset mapping relationship, obtaining the number of the target test cases, obtaining the priority of the target function name corresponding to each target test case if the number of the target test cases is greater than the preset number, and outputting a prompt message according to the target function name whose priority is greater than the preset priority, after modifying the function corresponding to the target function name whose priority is greater than the preset priority, until the number of target test cases is less than or equal to the preset number.
[0101] Optionally, the test case acquisition device 200 further includes: a sample acquisition module, a test report acquisition module, a function name extraction module and a creation module;
[0102] A sample acquisition module, used to acquire a sample source code, wherein the sample source code at least includes a function corresponding to the target function name;
[0103] A test report acquisition module is used to test the sample source code using a plurality of test cases through a preset tool to obtain a test report;
[0104] A function name extraction module, used to extract multiple function names from the test report;
[0105] An establishing module is used to establish the preset mapping relationship according to the multiple function names and the multiple test cases.
[0106] Optionally, the preset tool includes a C++ code analysis tool or a Python code analysis tool.
[0107] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0108] Figure 7 FIG. 7 is a block diagram of an electronic device 700 according to an exemplary embodiment. Figure 7 As shown, the electronic device 700 may include: a processor 701 and a memory 702. The electronic device 700 may also include one or more of a multimedia component 703, an input / output (I / O) interface 704, and a communication component 705.
[0109] The processor 701 is used to control the overall operation of the electronic device 700 to complete all or part of the steps in the test case acquisition method described above. The memory 702 is used to store various types of data to support the operation of the electronic device 700, and these data may include, for example, instructions for any application or method used to operate on the electronic device 700, and application-related data, such as contact data, sent and received messages, pictures, audio, video, etc. The memory 702 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, referred to as EPROM), programmable read-only memory (Programmable Read-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic memory, flash memory, disk or optical disk. The multimedia component 703 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may be further stored in the memory 702 or sent through the communication component 705. The audio component also includes at least one speaker for outputting audio signals. The I / O interface 704 provides an interface between the processor 701 and other interface modules, and the other interface modules may be keyboards, mice, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 705 is used for wired or wireless communication between the electronic device 700 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IOT, eMTC, or other 5G, etc., or a combination of one or more of them, is not limited here. Therefore, the corresponding communication component 705 may include: Wi-Fi module, Bluetooth module, NFC module, etc.
[0110] In an exemplary embodiment, the electronic device 700 can be implemented by one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), controllers, microcontrollers, microprocessors or other electronic components to execute the above-mentioned test case acquisition method.
[0111] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, and when the program instructions are executed by a processor, the steps of the test case acquisition method described above are implemented. For example, the computer-readable storage medium may be the memory 702 including the program instructions described above, and the program instructions may be executed by the processor 701 of the electronic device 700 to complete the test case acquisition method described above.
[0112] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above test case acquisition method when executed by the programmable device.
[0113] In summary, the test case acquisition method, device, medium and electronic device provided by the present invention, the source code to be tested is the source code modified on the basis of the original test source code, and when the source code to be tested needs to be tested, only the modified part needs to be tested. Therefore, the target function name corresponding to the function at the modified position in the source code to be tested is obtained, and based on the preset mapping relationship, the target test case corresponding to the target function name is determined from multiple test cases in the database. The target test case obtained according to the target function name corresponding to the modified position is used to test the source code corresponding to the modified position. There is no need to test the entire source code to be tested, which can reduce the test intensity, shorten the test time, and thus shorten the development cycle.
[0114] The preferred embodiments of the present disclosure are described in detail above in conjunction with the accompanying drawings; however, the present disclosure is not limited to the specific details in the above embodiments. Within the technical concept of the present disclosure, a variety of simple modifications can be made to the technical solution of the present disclosure, and these simple modifications all fall within the protection scope of the present disclosure.
[0115] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present disclosure will not further describe various possible combinations.
[0116] In addition, various embodiments of the present disclosure may be arbitrarily combined, and as long as they do not violate the concept of the present disclosure, they should also be regarded as the contents disclosed by the present disclosure.
Claims
1. A test case acquisition method, characterized in that: The method comprises: Obtaining a source code to be tested, wherein the source code to be tested is a source code obtained by modifying an original test source code; Extracting the target function name corresponding to the function at the modification position in the source code to be tested; Based on a preset mapping relationship, a target test case corresponding to the target function name is obtained from multiple test cases in a database, wherein the preset mapping relationship includes a correspondence between each function name and a corresponding test case, and the target test case is used to test the source code at the modified position in the source code to be tested.
2. The method according to claim 1, characterized in that Before extracting the function name corresponding to the function at the modified position in the source code to be tested as the target function name, the method further includes: According to the original test source code and the source code to be tested, a modification position in the source code to be tested is determined.
3. The method according to claim 2, characterized in that The step of determining the modification position in the source code to be tested according to the original test source code and the source code to be tested includes: By using preset instructions, the original test source code and the source code to be tested are compared to capture the modified line numbers in the source code to be tested; The modified line number is determined as the modified position.
4. The method according to claim 1, characterized in that There are multiple target test cases, each of which corresponds to at least one target function name. After acquiring the target test case corresponding to the target function name from multiple test cases in the database based on the preset mapping relationship, the method further includes: Obtaining the number of target test cases; If the number of the target test cases is greater than the preset number, obtain the priority of the target function name corresponding to each target test case, wherein the priority of the target function name is positively correlated with the number of times the target test case corresponding to the target function name is called; According to the target function name whose priority is greater than the preset priority, prompt information is output, wherein the prompt information is used to prompt to modify the function corresponding to the target function name whose priority is greater than the preset priority.
5. The method according to claim 4, characterized in that After outputting the prompt information according to the name of the target function whose priority is greater than the preset priority, the method further includes: After modifying the function corresponding to the target function name whose priority is greater than the preset priority, repeat the steps of obtaining the target test case corresponding to the target function name from multiple test cases in the database based on the preset mapping relationship, obtaining the number of the target test cases, obtaining the priority of the target function name corresponding to each target test case if the number of the target test cases is greater than the preset number, and outputting a prompt message according to the target function name whose priority is greater than the preset priority, until the number of target test cases is less than or equal to the preset number.
6. The method according to any one of claims 1 to 5, characterized in that: Before obtaining the target test case corresponding to the target function name from the multiple test cases in the database based on the preset mapping relationship, the method further includes: Obtaining a sample source code, wherein the sample source code at least includes a function corresponding to the target function name; Using a preset tool, using multiple test cases to test the sample source code, and obtaining a test report; extracting a plurality of function names from the test report; The preset mapping relationship is established according to the multiple function names and the multiple test cases.
7. The method according to claim 6, characterized in that The preset tool includes a C++ code analysis tool or a Python code analysis tool.
8. A test case acquisition device, characterized in that: The device: An acquisition module, used for acquiring a source code to be tested, wherein the source code to be tested is a source code obtained by modifying an original test source code; An extraction module, used for extracting the target function name corresponding to the function at the modification position in the source code to be tested; A mapping module is used to obtain a target test case corresponding to the target function name from multiple test cases in a database based on a preset mapping relationship, wherein the preset mapping relationship includes a correspondence between each function name and a corresponding test case, and the target test case is used to test the source code at the modified position in the source code to be tested.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.
10. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of claims 1 to 7.