Test case acquisition method, device, equipment, medium and product based on code file modification
By obtaining the mapping data between code files and associated test cases, the minimum effective test case collection is generated, which solves the problem of increased redundant test cases after merging code branches, improves development efficiency and accuracy, and achieves efficient code branch merge verification.
Patent Information
- Application Number
- CN202410905177.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-07-08
AI Technical Summary
In the process of software design and development, all test cases need to be run after the code branches are merged, which leads to an increase in redundant test cases, reduces development efficiency and increases running time. In addition, due to the difference in experience of different developers, there may be a risk of incomplete branch merge verification. .
By obtaining the mapping data between code files and associated test cases, a minimum valid test case collection is generated, and only associated test cases covering all modified code files are run, thereby reducing redundant test case runs and improving code branch merging efficiency.
It effectively reduces the running time of code branch merging, improves development efficiency, reduces human resource consumption, improves the accuracy of associated test cases, and avoids the risk of not running necessary test cases.
Smart Images

Figure CN118445214B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of software design and development, and in particular relates to a test case acquisition method, device, equipment, medium and product based on code file modification. Background Art
[0002] At each stage of the software design and development process, the editing and modification of code content is involved. After the relevant developers have modified the code content, they usually need to submit the modified code content to the version control warehouse through the code branch merge process. After executing the code branch merge, all test cases usually need to be run in sequence to ensure the accuracy of the branch merge process and avoid abnormal operation caused by the branch merge process.
[0003] In the related art, after the code branch is merged, it is usually necessary to run all the test cases in the test case library. When the code modification amount is small, most of the test cases are redundant test cases. Running all the test cases will reduce the development efficiency, and as the number of test cases in the test case library continues to increase, the running time will also continue to increase.
[0004] In this regard, the current method is to select a part of the test cases from the test case library for running according to the product directory to which the modified code file belongs, or to select a part of the test cases for running according to the classification tags of each test case in the test case library. However, the method of selecting test cases based on the product directory to which the code file belongs still has a considerable number of redundant test cases, which cannot effectively reduce the running time. In addition, for code files containing underlying public functions, it is not possible to select the test cases to be executed by simple product classification, and all test cases still need to be run; in the method of selecting according to the classification tags of the test cases, developers are required to mark each test case with a classification tag, which takes up the development time of the developers and affects the overall development efficiency of the project. In addition, since different developers inevitably have differences in development experience and understanding of the project, there may be a risk of missing tags, which leads to a greatly increased risk of failing to run the necessary test cases and incomplete verification of the branch merge process. Summary of the invention
[0005] The present invention provides a test case acquisition method, device, equipment, medium and product based on code file modification, which can improve the technical problem in the related art that a large number of redundant test cases exist when test case verification is performed after code changes, which affects development efficiency and increases running time.
[0006] In a first aspect, the present invention provides a method for acquiring a test case based on code file modification, the method comprising:
[0007] In response to the modification submission instruction, all code files that have been modified are obtained;
[0008] Obtaining a first corresponding relationship; wherein the first corresponding relationship includes mapping data between each code file and a corresponding associated test case;
[0009] According to the first corresponding relationship, the associated test cases corresponding to each modified code file are respectively obtained to obtain a minimum valid test case collection consisting of all the associated test cases.
[0010] Optionally, in response to the modification submission instruction, before obtaining all code files that have been modified, the method further includes:
[0011] Compile all code files in the project to generate executable files;
[0012] Use the executable file to traverse and run each test case to be run in the complete test case collection to obtain the code coverage of each code file corresponding to the test case to be run;
[0013] Compare the code coverage of each code file corresponding to the test case to be run with the basic coverage of each code file, and select the code files with different code coverage and basic coverage as the code files associated with the test case to be run; wherein the basic coverage is the code coverage of each code file corresponding to the basic test case when the executable file runs;
[0014] According to all the test cases to be run and their associated code files, a first correspondence between the code files and the test cases is generated.
[0015] Optionally, before using the executable file to traverse and run each to-be-run test case in the complete test case collection to obtain the code coverage of each code file corresponding to the to-be-run test case, the method further includes:
[0016] Use the executable file to run the basic test case, and generate the basic coverage of each code file corresponding to the basic test case based on the running results;
[0017] Generate a basic code coverage relationship based on the basic coverage of basic test cases corresponding to each code file.
[0018] Optionally, use the executable file to run the basic test case, and generate the basic coverage of the basic test case corresponding to each code file according to the running result, including:
[0019] Use the executable file to run the basic test case to obtain the code structure Gcno file and coverage Gcda file corresponding to each code file;
[0020] Convert the Gcno file and Gcda file corresponding to each code file into the first Gcov file;
[0021] Parse the first Gcov file corresponding to each code file to obtain the basic coverage of the basic test case corresponding to each code file.
[0022] Optionally, the data type in the basic code coverage relationship is a key-value pair type, the key name includes the code file, and the key value includes the coverage rate.
[0023] Optionally, before using the executable file to traverse and run each test case to be run in the complete test case collection, the following step is also included:
[0024] According to the preset filtering rules, test cases whose file names meet the preset filtering rules are filtered out from the test case library to form a complete test case collection.
[0025] Optionally, comparing the code coverage of each code file corresponding to the test case to be run with the basic coverage of each code file, and selecting code files with different code coverage and basic coverage as code files associated with the test case to be run, including:
[0026] Obtain the second Gcov files corresponding to the code files obtained after the executable file runs the test case to be run;
[0027] For each code file, parse the second Gcov file corresponding to the code file to obtain the corresponding code coverage, and compare the code coverage with the basic coverage corresponding to the code file;
[0028] When the code coverage of the code file is different from the basic coverage, mapping data between the code file and the test case to be run is generated until the second Gcov files corresponding to all code files are traversed and parsed, and the first mapping relationship corresponding to the test case to be run is obtained according to the generated mapping data.
[0029] Optionally, the first corresponding relationship includes a first mapping relationship corresponding to each test case to be run.
[0030] Optionally, the method further comprises:
[0031] In response to the modification submission instruction, all test cases that have been modified are obtained;
[0032] All test cases that have been modified are added to the unmapped data table; wherein the minimum valid test case collection also includes all test cases in the unmapped data table.
[0033] Optionally, after adding all modified test cases to the unmapped data table, the following is also included:
[0034] Get the test cases to be updated from the unmapped data table;
[0035] Utilize the executable file to traverse and run each test case to be updated, and determine the code file associated with the test case to be updated based on the code coverage of each code file corresponding to the test case to be updated and the basic coverage of each code file;
[0036] Based on each test case to be updated and the code file associated therewith, the first corresponding relationship and the unmapped data table are updated.
[0037] Optionally, based on each test case to be updated and the code file associated therewith, updating the first correspondence and the unmapped data table includes:
[0038] For each test case to be updated, deleting the original mapping data corresponding to the test case to be updated in the first corresponding relationship;
[0039] Adding the code file associated with the test case to be updated and the mapping data of the test case to be updated into a first corresponding relationship;
[0040] Delete the test case to be updated from the unmapped data table.
[0041] Optionally, the initial state of each test case in the unmapped data table is the first state; obtaining the test case to be updated from the unmapped data table includes:
[0042] Obtain the test case in the first state from the unmapped data table as the test case to be updated;
[0043] Before using the executable file to run the test case to be updated, the test case to be updated is changed from the first state to the second state.
[0044] In a second aspect, the present invention provides a test case acquisition device based on code file modification, comprising:
[0045] A file determination module, for obtaining all code files that have been modified in response to a modification submission instruction;
[0046] An acquisition module, used to acquire a first corresponding relationship; wherein the first corresponding relationship includes mapping data between each code file and a corresponding associated test case;
[0047] The test case selection module is used to obtain the associated test cases corresponding to each modified code file according to the first corresponding relationship, and obtain a minimum valid test case collection consisting of all the associated test cases.
[0048] In a third aspect, the present invention provides a test case acquisition device based on code file modification, the test case acquisition device based on code file modification includes:
[0049] a processor and a memory storing computer program instructions;
[0050] When the processor executes the computer program instructions, the steps of the test case acquisition method based on code file modification in the first aspect are implemented.
[0051] In a fourth aspect, the present invention provides a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implement the steps of the test case acquisition method based on code file modification in the first aspect.
[0052] In a fifth aspect, the present invention provides a computer program product, which includes a computer program. When the instructions in the computer program product are executed by a processor, the steps of the test case acquisition method based on code file modification in the first aspect are implemented.
[0053] The test case acquisition method, device, equipment, medium and product based on code file modification of the present invention can determine all code files that have been modified when relevant personnel submit modifications to code files during the code branch merging process. After obtaining the first corresponding relationship, the associated test cases corresponding to each code file that has been modified can be determined separately according to the mapping data between the code file and the associated test case in the first corresponding relationship. After integrating all the associated test cases corresponding to all code files, a minimum valid test case collection can be obtained, and the associated test cases contained in the minimum valid test case collection cover all code files that have been modified. In the process of executing the code branch merging, it is only necessary to execute all the associated test cases in the minimum valid test case collection to complete the correctness verification of the code branch merging, thereby reducing the running time of the code branch merging and improving the efficiency of the code branch merging. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the following is a brief introduction to the drawings required for use in the embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0055] Figure 1 It is a flowchart of a method for obtaining a test case based on code file modification provided by an embodiment of the present invention;
[0056] Figure 2 is a flow chart of a method for acquiring a test case based on code file modification provided by another embodiment of the present invention;
[0057] Figure 3 It is a flowchart of a test case acquisition method based on code file modification provided by another embodiment of the present invention;
[0058] Figure 4This is one of the flow charts of a method for acquiring a test case based on code file modification provided by yet another embodiment of the present invention;
[0059] Figure 5 This is a second flow chart of a method for acquiring a test case based on code file modification provided by yet another embodiment of the present invention;
[0060] Figure 6 It is a schematic diagram of a Pipeline management process provided by an embodiment of the present invention;
[0061] Figure 7 It is a structural schematic diagram of a test case acquisition device based on code file modification provided by an embodiment of the present invention;
[0062] Figure 8 It is a structural schematic diagram of a test case acquisition device based on code file modification provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0063] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present invention, rather than to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.
[0064] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0065] At each stage of the software design and development process, the editing and modification of code content is involved. After the relevant developers have modified the code content, they usually need to submit the modified code content to the version control warehouse through the code branch merge process. After executing the code branch merge, all test cases usually need to be run in sequence to ensure the accuracy of the branch merge process and avoid abnormal operation caused by the branch merge process.
[0066] In the related art, after the code branch is merged, it is usually necessary to run all the test cases in the test case library. When the code modification amount is small, most of the test cases are redundant test cases. Running all the test cases will reduce the development efficiency, and as the number of test cases in the test case library continues to increase, the running time will also continue to increase.
[0067] In this regard, the current method is to select a part of the test cases from the test case library for running according to the product directory to which the modified code file belongs, or to select a part of the test cases for running according to the classification tags of each test case in the test case library. However, the method of selecting test cases based on the product directory to which the code file belongs still has a considerable number of redundant test cases, which cannot effectively reduce the running time. In addition, for code files containing underlying public functions, it is not possible to select the test cases to be executed by simple product classification, and all test cases still need to be run; in the method of selecting according to the classification tags of the test cases, developers are required to mark each test case with a classification tag, which takes up the development time of the developers and affects the overall development efficiency of the project. In addition, since different developers inevitably have differences in development experience and understanding of the project, there may be a risk of missing tags, which leads to a greatly increased risk of failing to run the necessary test cases and incomplete verification of the branch merge process.
[0068] In order to solve at least one of the above technical problems, the embodiments of the present invention provide a method, device, equipment, medium and product for obtaining test cases based on code file modification. The following first introduces the method for obtaining test cases based on code file modification provided by the embodiments of the present invention.
[0069] Figure 1 A flow chart of a method for acquiring a test case based on code file modification provided by an embodiment of the present invention is shown. The method may include the following steps:
[0070] S110, in response to the modification submission instruction, obtaining all code files that have been modified;
[0071] S120, obtaining a first corresponding relationship; wherein the first corresponding relationship includes mapping data between each code file and a corresponding associated test case;
[0072] S130, obtaining associated test cases corresponding to each modified code file according to the first corresponding relationship, and obtaining a minimum valid test case collection consisting of all associated test cases.
[0073] In this embodiment, during the code branch merging process, when relevant personnel submit modifications to code files, all code files that have undergone modifications can be determined. After obtaining the first corresponding relationship, the associated test cases corresponding to each code file that has undergone modifications can be determined separately based on the mapping data between the code file and the associated test case in the first corresponding relationship. After integrating all the associated test cases corresponding to all code files, a minimum valid test case collection can be obtained, and the associated test cases contained in the minimum valid test case collection cover all code files that have undergone modifications. In the process of executing the code branch merge, it is only necessary to execute all the associated test cases in the minimum valid test case collection to complete the correctness verification of the code branch merge, thereby reducing the running time of the code branch merge and improving the efficiency of the code branch merge.
[0074] It should be noted that since the minimum granularity in the above implementation is the code file, it can also work normally for the underlying public functions and will not be affected by the product type. That is, it has good compatibility for different engineering projects. In addition, the above implementation can be automatically run through an automation framework, and no relevant personnel need to participate in the process of determining the minimum valid test case collection, which can effectively reduce the consumption of human resources, avoid the influence of the development experience of relevant personnel on the actual results, and improve the accuracy of the associated test cases obtained.
[0075] The specific implementation methods of the above steps are introduced below.
[0076] In S110, during the process of designing and developing the engineering project, relevant personnel can trigger the corresponding modification submission instruction after writing the code file to merge the written or modified code file as a branch to realize the code branch merging function. After receiving the modification submission instruction triggered by the relevant personnel, the device can determine all the code files that have been modified and changed involved in this modification submission in response to the modification submission instruction.
[0077] In S120, the device may obtain a pre-generated first correspondence relationship, where the first correspondence relationship includes mapping data between each code file and a corresponding associated test case.
[0078] Before executing the code branch merging operation, the device can determine one or more associated test cases corresponding to each code file from all test cases, obtain mapping data between the code file and the corresponding associated test case, and generate a first correspondence relationship based on multiple mapping data. When a code file is modified, one or more associated test cases corresponding to each modified code file can be determined based on the first correspondence relationship, and all associated test cases can be sorted and summarized to obtain all test cases that need to be executed during this code branch merging process.
[0079] Please refer to Figure 2 In some embodiments, before S110, the following steps may also be included:
[0080] S210, compile all code files in the project to generate executable files;
[0081] S220, using the executable file to traverse and run each test case to be run in the complete test case collection, and obtain the code coverage rate of each code file corresponding to the test case to be run;
[0082] S230, comparing the code coverage of each code file corresponding to the test case to be run with the basic coverage of each code file, and selecting code files with different code coverage and basic coverage as code files associated with the test case to be run; wherein the basic coverage is the code coverage of each code file corresponding to the basic test case when the executable file runs;
[0083] S240: Generate a first correspondence between code files and test cases according to all the test cases to be run and their associated code files.
[0084] In this embodiment, for a specific engineering project, the code file can be compiled to obtain an executable file. By using the executable file to traverse and run each test case to be run, the code coverage of each code file corresponding to each test case to be run can be obtained. Under each test case to be run, according to the code coverage of each code file corresponding to the test case to be run and the basic coverage of the corresponding basic test case, it can be determined whether the test case to be run covers the code file, and the code file associated with each test case to be run is determined according to the comparison result of the code coverage and the basic coverage. After obtaining the code files associated with all the test cases to be run, the first correspondence between the code file and the test case can be generated.
[0085] In S210, for a project specified by a user, the device may obtain all code files in the project, and compile the code files to obtain an executable file of the project.
[0086] It should be noted that the above-mentioned compilation process may include preprocessing the source code in the code file, such as macro replacement, header file inclusion, etc., to generate preprocessed source code. The compiler included in the device may translate the preprocessed source code into an intermediate code of assembly language or machine language to obtain a target file.
[0087] The target file usually contains information such as binary code, symbol table and relocation table. The linker included in the device can link the target file and the library file. The linking process includes symbol resolution, relocation and other operations, which associate other functions and variables referenced in the target file with the functions and variables in the library file to generate the final executable file.
[0088] In S220, after the executable file of the engineering project is generated, the executable file can be used to traverse and run each test case to be run in the complete test case collection to obtain the code coverage of each code file corresponding to each test case to be run.
[0089] Take the above executable file containing 10 code files and the complete test case collection containing 20 test cases to be run as an example. In the process of obtaining code coverage, you can use the executable file to run one of the test cases to be run, and get 10 code coverage rates of the 10 code files corresponding to the test case to be run. After running the test case to be run, you can continue to run the next test case to be run, and get 10 code coverage rates of the 10 code files corresponding to the next test case to be run. After using the executable file to traverse and run 20 test cases to be run, you can get 20 code coverage rates of each code file in the 10 code files corresponding to the 20 test cases to be run. The numerical range of the above code coverage can be 0 to 100%.
[0090] It should be noted that if you want to obtain the code coverage of each code file relative to the test case during the execution of the executable file, you need to enable the relevant tools that implement the code coverage function during the aforementioned compilation process to generate the executable file. For example, the compilation parameters of the relevant tools can be set accordingly during the compilation process. Taking the code coverage statistics tool GCOV as an example, the compilation parameters -fprofile-arcs and -ftest-coverage can be added during the compilation process of the executable file.
[0091] Please refer to Figure 3 In some embodiments, before the above S220, the following steps may also be included:
[0092] S310, running the basic test case using the executable file, and generating the basic coverage of the basic test case corresponding to each code file according to the running result;
[0093] S320: Generate a basic code coverage relationship based on the basic coverage rate of each code file corresponding to the basic test case.
[0094] In this embodiment, before using the executable file to run each test case to be run in the complete test case collection, the executable file can be used to run the basic test case to obtain the basic coverage rate corresponding to each code file, and generate a basic code coverage relationship based on each code file and the corresponding basic coverage rate. After the basic code coverage relationship is generated, in the subsequent process of the executable file traversing each test case to be run, the basic coverage rate corresponding to the corresponding code file can be directly read from the basic code coverage relationship.
[0095] In S310 , before using the executable file to traverse and run each test case to be run in the complete test case collection, the basic test case may be run using the executable file first.
[0096] The basic test case may not contain any operations or may only contain default parameter settings. For example, the basic test case may contain the following:
[0097] set_runtime_flag db_infer_wide_operators 1
[0098] set_param cdc.check_continue_on_sdc_error true
[0099] config_message-golden_log_style TRUE;
[0100] The above content is the default parameter setting included in the basic test case. After running the basic test case using the executable file, the basic coverage of each code file corresponding to the basic test case can be generated according to the running results. For example, taking the example that the executable file contains 10 code files, after the executable file runs the basic test case, the basic coverage corresponding to each of the 10 code files can be obtained.
[0101] The basic code coverage relationship obtained after the executable file runs the basic test case may include a code file-basic coverage data table BSCT (Basic Source-Coverage Table). In an optional implementation, part of the content of BSCT is as follows:
[0102]
[0103] Each line in BSCT includes mapping data between a code file and basic coverage. code is the code file, product is the project, gcov is the Gcov file corresponding to the code file after the executable file runs the basic test case, and cov is the basic coverage obtained by parsing the Gcov file. NULL in the basic coverage means the basic coverage is 0, and the maximum value of the basic coverage, 100.0000, means the basic coverage is 100%.
[0104] In some embodiments, the above S310 may include:
[0105] S410, using the executable file to run the basic test case, and obtain the code structure Gcno file and coverage Gcda file corresponding to each code file;
[0106] S420, converting the Gcno file and the Gcda file corresponding to each code file into a first Gcov file;
[0107] S430, parsing the first Gcov file corresponding to each code file to obtain the basic coverage of the basic test case corresponding to each code file.
[0108] In this embodiment, the basic test case is run using an executable file to obtain the Gcno file and Gcda file corresponding to each code file. By converting the Gcno file and the Gcda file, the first Gcov file corresponding to the code file can be obtained, and the basic coverage corresponding to the code file can be obtained by parsing the first Gcov file.
[0109] In S410, after adding the compilation parameters of the code coverage tool during the compilation process, the basic test cases are run using the executable file to generate the code structure Gcno file and coverage Gcda file corresponding to each code file. Among them, the Gcno file is a file format generated by the GCC compiler, which records the control flow information of the program, including the execution status of functions, code blocks, branches, etc.; the Gcda file is a file generated when the program is running, which records the execution information of the program, including the number of times each code block is executed, the code blocks that are not executed, and other information.
[0110] In S420, for each Gcno file and Gcda file corresponding to the code file, the Gcov tool can be used to convert them into the first Gcov file corresponding to the code file. The Gcov tool is a code coverage analysis tool in the GNU tool chain. When the executable file is finished running, the Gcov tool is used to read the .gcno and .gcda files to generate a code coverage report. The code coverage report includes the coverage statistics of the program, such as the number of executions and the number of lines of each function and each code block. The Gcov tool can generate a Gcov file, which contains the source code and test coverage data of the program and is used to analyze the test coverage of the code file.
[0111] In S430, after the first Gcov file corresponding to each code file is obtained through conversion, the basic coverage of each code file under the basic test case corresponding to the code file can be obtained by parsing the first Gcov file corresponding to each code file.
[0112] In S320, after obtaining the basic coverage of each code file corresponding to the basic test case, each code file and its corresponding basic coverage can be used as a mapping data of the basic code coverage, and the mapping data corresponding to multiple code files can be combined to obtain the basic code coverage relationship.
[0113] In some embodiments, the data type in the above-mentioned basic code coverage relationship can be a key-value pair type. The key name includes the code file, and the key value includes the coverage rate. That is, each mapping data in the basic code coverage relationship can include a key-value pair of code file-coverage rate. In addition, each mapping data in the basic code coverage relationship can also be stored in other data types, which is not limited here.
[0114] In some embodiments, before the above S220, the following steps may also be included:
[0115] According to the preset filtering rules, test cases whose file names meet the preset filtering rules are filtered out from the test case library to form a complete test case collection.
[0116] In this embodiment, before using the executable file to run the test case to be run, it is necessary to identify the test case corresponding to the engineering project from the test case library. The method of filtering the test cases to be run from the test case library can be, based on the preset filtering rules, filtering the test cases whose file suffixes (file extensions) meet the preset filtering rules from the test case library, and arranging the filtered test cases into a complete test case collection.
[0117] The device can filter out files with a file suffix of .tcl from the test case library to form a complete test case collection. As an optional implementation, the test case files included in the complete test case collection are as follows:
[0118]
[0119] As an optional implementation, the test case library contains test cases for multiple engineering projects. When merging code branches for a single engineering project, the preset filtering rules can also be to use the name or abbreviation of the engineering project as a keyword, and filter out test cases whose path names contain the keywords from the test case library as a complete test case collection.
[0120] In S230, after the code coverage of each code file corresponding to each test case to be run is obtained, taking one of the test cases to be run as an example, for each code file, the code coverage of the code file corresponding to the test case to be run can be compared with the basic coverage of the code file.
[0121] The basic coverage rate of each code file may be the code coverage rate corresponding to each code file obtained when the basic test case is run using the executable file in the above embodiment.
[0122] If the code coverage of the code file corresponding to the test case to be run is consistent with the basic coverage of the code file, it means that the test case to be run does not cover the code file.
[0123] The above-mentioned test case to be run does not cover a certain code file, which means that when the executable file runs the test case to be run, the code content in the code file is not involved or called. Therefore, if the code content in the code file is modified, the test case to be run is not an associated test case of the code file. That is, when the code file is modified, the test case to be run may not be run.
[0124] If the code coverage of the code file corresponding to the test case to be run is different from the basic coverage of the code file, it means that the test case to be run covers the code file. At this time, the code file can be associated with the test case to be run. That is, the code file is the code file associated with the test case to be run. Correspondingly, the test case to be run is also the test case associated with the code file.
[0125] For each test case to be run, it can be determined whether the code coverage and basic coverage corresponding to each code file are the same, and the code files with different code coverage and basic coverage are used as the code files associated with the test case to be run.
[0126] It should be noted that the above code coverage is different from the basic coverage. The code coverage may be greater than the basic coverage, or the code coverage may be less than the basic coverage.
[0127] After all the test cases to be run are traversed and run using the executable file, one or more code files associated with each test case to be run can be obtained.
[0128] In some embodiments, the above S230 may include:
[0129] S510, obtaining second Gcov files corresponding to respective code files obtained after the executable file runs the test case to be run;
[0130] S520, for each code file, parsing a second Gcov file corresponding to the code file to obtain a corresponding code coverage, and comparing the code coverage with a basic coverage corresponding to the code file;
[0131] S530, when the code coverage of the code file is different from the basic coverage, generate mapping data between the code file and the test case to be run, until the second Gcov files corresponding to all code files are traversed and parsed, and the first mapping relationship corresponding to the test case to be run is obtained according to the generated mapping data.
[0132] In this embodiment, after the test case to be run is run using an executable file, a second Gcov file corresponding to each code file can be obtained. The code coverage corresponding to each code file under the test case to be run can be obtained by parsing the second Gcov file. After comparing the code coverage with the basic coverage, if the code coverage is different from the basic coverage, it means that the test case to be run covers the code file, that is, the test case to be run has an association relationship with the code file, and mapping data between the code file and the test case to be run can be generated at this time. After traversing all the second Gcov files, multiple mapping data can be obtained, and multiple mapping data can form a first mapping relationship of the test case to be run.
[0133] In S510, taking a single test case to be run as an example, since the compilation parameters associated with the code coverage function are enabled during the compilation of the executable file, after the test case to be run is run using the executable file, multiple second Gcov files can be generated, and the multiple second Gcov files correspond one-to-one to the multiple code files.
[0134] In S520, for each code file, the second Gcov file corresponding to the code file may be parsed to obtain the code coverage corresponding to the code file.
[0135] Since the basic coverage of each code file has been obtained when the executable file is used to run the basic test case in the above embodiment, after parsing the second Gcov file to obtain the code coverage corresponding to the code file, the basic coverage corresponding to the code file can be directly read, and the code coverage and the basic coverage can be compared to determine whether they are the same.
[0136] In S530, when the code coverage of a certain code file is different from the basic coverage, it can be determined that the running test case covers the code file. At this time, mapping data between the code file and the test case to be run can be generated.
[0137] After a test case to be run is run using an executable file and mapping data between a portion of the code file and the test case to be run is obtained, a first mapping relationship corresponding to the test case to be run can be obtained according to the generated mapping data.
[0138] For example, in a single test case to be run, among the 10 code files obtained, there are 4 code files whose code coverage is different from the basic coverage, then mapping data between each of the 4 code files and the test case to be run can be generated respectively, for a total of 4 mapping data. The first mapping relationship corresponding to the test case to be run includes 4 mapping data.
[0139] The following is part of the Code-Case Map (CCM) of the code file-test case mapping relationship obtained after the executable file runs a single test case to be run:
[0140]
[0141] code is a code file, and test_case is a test case. Each line in CCM includes mapping data of a code file and a test case. It can be understood that the above CCM is the first mapping relationship between a single test case to be run and its associated multiple code files, and in each mapping data of CCM, the test case remains consistent.
[0142] In some embodiments, the first corresponding relationship includes a first mapping relationship corresponding to each test case to be run.
[0143] After the executable file is used to sequentially run each test case to be run and the first mapping relationship corresponding to each test case to be run is obtained, a first corresponding relationship consisting of a plurality of first mapping relationships can be obtained.
[0144] After the executable file runs all the test cases to be run, part of the content of the code-case table (CCT) composed of multiple CCMs is as follows:
[0145]
[0146] code is a code file, and test_case is a test case. Each line in CCT includes mapping data of a code file and a test case. It can be understood that after obtaining multiple CCMs, the multiple CCMs are merged to obtain CCT.
[0147] As an optional implementation, taking the above-mentioned executable file including 10 code files as an example, in a single test case to be run, after obtaining the code coverage of each code file, it can be determined whether the code coverage of the code file is consistent with the basic coverage. If the code coverage of the code file is inconsistent with the basic coverage, mapping data between the code file and the test case to be run can be generated, and the generated mapping data can be stored in the database. Therefore, in the above implementation, if there are 4 code files whose code coverage is different from the basic coverage, after completing the comparison of the code coverage of the 10 code files with the basic coverage, 4 mapping data can be generated and stored in the database. At this time, the 4 mapping data stored in the database are the first mapping relationship corresponding to the test case to be run.
[0148] When the next test case to be run is run using the executable file, the code coverage of each code file corresponding to the next test case to be run can also be compared with the basic coverage, and when the code coverage of a certain code file is inconsistent with the basic coverage, the mapping data between the code file and the next test case to be run is stored in the database. After the last test case to be run is completed and the code coverage of all code files in the last test case to be run is compared with the basic coverage, all the mapping data stored in the database constitute a first corresponding relationship.
[0149] It should be noted that the data type of the mapping data stored in the database can be a key-value pair. The key name of the key-value pair can be the file name of the code file, and the key value can be the test case to be run. In addition, the mapping data can also be stored in other data types, which is not limited here.
[0150] In S240, after running each test case to be run using the executable file, the code file associated with the test case to be run can be obtained based on the judgment result of whether the code coverage of each code file is consistent with the basic coverage. After traversing and running all the test cases to be run, the code file associated with each test case to be run can be obtained. Based on the code file corresponding to each test case to be run, a first correspondence between the code file and the test case can be generated.
[0151] In S130, after the first corresponding relationship is obtained, the associated test cases corresponding to each modified code file may be obtained according to the first corresponding relationship.
[0152] The above first correspondence includes the association relationship of the test case code files to be run. For a single modified code file, one or more associated test cases corresponding to it can be determined in the first correspondence. When there are multiple modified code files, the associated test cases corresponding to each modified code file can be determined in turn according to the first correspondence.
[0153] Since the associated test cases corresponding to different code files may overlap, after all the associated test cases are obtained, all the associated test cases can be de-overlapped and merged to obtain a minimum valid test case collection.
[0154] After obtaining the minimum valid test case collection, only each test case in the minimum valid test case collection can be run during the code branch merging process, thereby reducing the test running time during the code branch merging process and improving the efficiency of the code branch merging.
[0155] Please refer to Figure 4 In some embodiments, the test case acquisition method based on code file modification may further include:
[0156] S610, in response to the modification submission instruction, obtaining all test cases that have been modified;
[0157] S620: Add all the modified test cases to the unmapped data table; wherein the minimum valid test case collection also includes all the test cases in the unmapped data table.
[0158] In this embodiment, when the relevant personnel submit the modification of the test case, the test case that has been modified can be determined, and the test case is added to the unmapped data table. When generating the minimum valid test case collection, not only the associated test case corresponding to each code file is obtained according to the first correspondence, but also all the test cases in the unmapped data table need to be added to the minimum valid test case collection. That is, when the code file is modified, the test cases that need to be run and verified also include all the test cases that have been modified before.
[0159] In S610, the relevant personnel may also modify the test case during the process of designing and developing the project. After receiving the modification submission instruction triggered by the relevant personnel, the device needs to determine the file type of the modified file submitted by the relevant personnel.
[0160] If the modified file is a code file, the operation steps in the above embodiment are executed to finally determine the minimum valid test case collection corresponding to this modification submission process.
[0161] If the modified file is a test case file, then in response to the modification submission instruction, all the modified test cases involved in the modification submission can be determined.
[0162] In S620 , after all the modified test cases are determined, all the modified test cases may be added to an unmapped case table (UCT).
[0163] In the above implementation of generating a minimum valid test case collection, if the unmapped data table contains at least one test case, the ultimately obtained minimum valid test case collection should also contain all test cases in the unmapped data table.
[0164] In the above implementation, if the relevant personnel modify some test cases, after the modification is submitted, the changed test cases will be added to the unmapped data table. When the code file is modified and submitted, all the test cases in the unmapped data table also need to be added to the minimum valid test case collection finally generated. That is, if a test case is modified, then during the code branch merging process, the modified test case needs to be added to the test case collection, so that the modified test case can be run and tested in the test case running link of the code branch merging, thereby verifying whether there are any abnormalities in the code branch merging process.
[0165] Please continue to refer to Figure 4 In some embodiments, after the above S620, the following steps may also be included:
[0166] S630, obtaining the test case to be updated from the unmapped data table;
[0167] S640, using the executable file to traverse and run each test case to be updated, and determining the code file associated with the test case to be updated based on the code coverage of each code file corresponding to the test case to be updated and the basic coverage of each code file;
[0168] S650: Based on each test case to be updated and the code file associated therewith, update the first corresponding relationship and the unmapped data table.
[0169] In this embodiment, the device can dynamically update the test cases to be updated in the unmapped data table. By using the executable file to traverse each test case to be updated in the unmapped data table in turn, the code coverage and basic coverage of each code file under each test case to be updated can be obtained. By judging whether the code coverage is consistent with the basic coverage, it can be determined whether the code file is associated with the test case to be updated. After obtaining the code file associated with each test case to be updated, the mapping data related to the test case to be updated in the first corresponding relationship can be updated, and the test case to be updated can be deleted from the unmapped data table.
[0170] In S630, the device may dynamically update the test cases in the unmapped data table in response to a related instruction triggered by the user or at a preset interval. During the dynamic update process, the device may obtain the test cases to be updated from the unmapped data table.
[0171] In some embodiments, the initial state of each test case in the unmapped data table is the first state; the above S630 may include:
[0172] S710, obtaining a test case in a first state from an unmapped data table as a test case to be updated;
[0173] S720: Before using the executable file to run the test case to be updated, change the test case to be updated from a first state to a second state.
[0174] In this embodiment, after the test case is modified and added to the unmapped data table, the initial state of the test case is the first state. During the dynamic update process, a test case in the first state of the unmapped data table can be obtained as a test case to be updated, and after its state is changed to the second state, the test case to be updated is run using an executable file.
[0175] In S710, after the relevant personnel submit the modified test case, the test case is added to the unmapped data table, and the initial state of the test case is the first state. The device can obtain the test case in the first state from the unmapped data table and use it as the test case to be updated.
[0176] In S720, after acquiring the test case in the first state as the test case to be updated, the device may change the state of the test case to be updated from the first state to the second state, and then use the executable file to run the test case to be updated to achieve dynamic update of the unmapped data table.
[0177] In S640, after the test cases to be updated are obtained from the unmapped data table, each test case to be updated may be traversed and run using the executable file.
[0178] During the traversal operation, before each traversal of a test case to be updated, the test case to be updated may be changed from the first state to the second state. For example, the test case to be updated may include a state value, where the state value off indicates the first state and the state value on indicates the second state.
[0179] Taking a single test case to be updated as an example, after the test case to be updated is changed from the first state to the second state, the test case to be updated can be run using an executable file.
[0180] After the executable file runs the test case to be updated, the code coverage of each code file corresponding to the test case to be updated can be obtained. The code coverage of each code file is compared with the basic coverage. Based on whether the code coverage is consistent with the basic coverage, it can be determined whether each code file has an association with the test case to be updated.
[0181] After comparing the code coverage of each code file with the basic coverage, a portion of code files associated with the test case to be updated can be obtained. The portion of code files is the code files that are re-determined to have an associated relationship with the test case to be updated after the test case to be updated is modified.
[0182] After the test case to be updated is completed and the code file associated with the test case to be updated is obtained, the executable file can be used to continue traversing the next test case to be updated until all test cases to be updated are traversed and run, and the code file associated with each test case to be updated is obtained.
[0183] In S650, after obtaining the code file associated with each test case to be updated, the first corresponding relationship may be updated based on each test case to be updated and the code file associated therewith, and the unmapped data table may be updated.
[0184] The updating of the first corresponding relationship may be to update the original associated code file of the test case to be updated in the first corresponding relationship.
[0185] Please refer to Figure 5 In some embodiments, the above S650 may include:
[0186] S810, for each test case to be updated, deleting the original mapping data corresponding to the test case to be updated in the first corresponding relationship;
[0187] S820, adding the mapping data of the code file associated with the test case to be updated and the test case to be updated into a first corresponding relationship;
[0188] S830: Delete the test case to be updated from the unmapped data table.
[0189] In this embodiment, after running the test case to be updated using an executable file, obtaining the code coverage of each code file based on the running result, and comparing the code coverage with the basic coverage, it is possible to determine the part of the code files associated with the test case to be updated after the modification, and generate new mapping data. After deleting the original mapping data related to the test case to be updated in the first corresponding relationship, the new mapping data can be added to the first corresponding relationship to achieve dynamic update of the first corresponding relationship. After adding the new mapping data of the test case to be updated to the first corresponding relationship, the test case to be updated can be deleted from the unmapped data table.
[0190] In S810, taking a single test case to be updated as an example, after obtaining the test case to be updated and the code file associated with it, the original mapping data corresponding to the test case to be updated in the first corresponding relationship may be deleted.
[0191] As an example implementation, if the number of original mapping data corresponding to the test case to be updated in the first corresponding relationship before the modification is made is 4, it means that the test case to be updated has an association relationship with 4 code files before the modification is made. That is, when any of the 4 code files is modified, the test case to be updated needs to be run and verified. Since the content of the test case to be updated has been modified, the association relationship before the modification will no longer be accurate. At this time, the 4 original mapping data corresponding to the test case to be updated can be deleted.
[0192] In S820, after deleting the original mapping data corresponding to the test case to be updated in the first correspondence, the re-determined code file and the mapping data of the test case to be updated can be added to the first correspondence based on the re-determined code file associated with the test case to be updated. That is, after deleting the original mapping data in the first correspondence, the new mapping data re-determined after the modification can be added again.
[0193] It should be noted that, for a single test case to be updated, the number of original mapping data and the number of new mapping data may be the same or different, and there is no limitation here.
[0194] In S830, for each test case to be updated, after deleting the original mapping data from the first corresponding relationship and adding new mapping data, the test case to be updated may be deleted from the unmapped data table.
[0195] When a user submits a modification to a code file, if the modified code file corresponds to one of the mapping data in the new mapping data, the test case to be updated will be added to the minimum valid test case collection as an associated test case corresponding to the modified code file.
[0196] On the contrary, if the modified code file is not the code file corresponding to any mapping data in the new mapping data, the test case to be updated will not be used as an associated test case corresponding to the modified code file, and since the test case to be updated has been deleted from the unmapped data table, the test case to be updated will not be added to the minimum valid test case collection.
[0197] Figure 6 The following is a schematic diagram of the Pipeline management process. Figure 6 As shown in the figure, in the code merge pipeline, if the user modifies the test case, such as adding a new test case or modifying the original test case, the modified test case can be passed to the UCT update pipeline. The UCT update pipeline can add the modified test case to the unmapped data table UCT.
[0198] When the CCT Update Pipeline fails to obtain the test cases to be updated from the unmapped data table UCT and perform updates, the Code Merge Pipeline can obtain the associated test cases of each code file from the original CCT based on the modified code files, and obtain all test cases from the unmapped data table UCT, and obtain the minimum valid test case collection by deduplicating the obtained test cases.
[0199] The CCT Update Pipeline can also obtain the test cases to be updated from the unmapped data table UCT in sequence for update. For each test case to be updated, the CCT Update Pipeline can update the CCM corresponding to the test case to be updated. When the unmapped data table UCT includes multiple test cases to be updated, the CCT Update Pipeline can update the CCMs corresponding to the multiple test cases to be updated respectively, and finally complete the update of the CCT.
[0200] After the CCT update pipeline reads all the test cases to be updated from the unmapped data table UCT and completes the update of CCT, all the test cases in the unmapped data table UCT are deleted. At this time, the code merge pipeline can obtain the associated test cases of each code file from the original CCT based on the modified code files, and organize them into a minimum valid test case collection.
[0201] After the CCT update pipeline reads some test cases to be updated from the unmapped data table UCT and completes the update of CCT, some test cases in the unmapped data table UCT that have completed the update are deleted. At this time, since the unmapped data table UCT is not empty, the code merge pipeline can obtain the associated test cases of each code file from the original CCT according to the modified code files, and combine them with the remaining test cases contained in the unmapped data table UCT to obtain the minimum valid test case collection.
[0202] Based on the same inventive concept, the present invention also provides a test case acquisition device based on code file modification. Figure 7 Provide detailed explanation.
[0203] Figure 7 It is a structural diagram of a test case acquisition device 1200 based on code file modification provided by an embodiment of the present invention.
[0204] like Figure 7 As shown, the test case acquisition device 1200 based on code file modification may include:
[0205] The first file determination module 1201 is used to obtain all code files that have been modified in response to the modification submission instruction;
[0206] The acquisition module 1202 is used to acquire a first corresponding relationship; wherein the first corresponding relationship includes mapping data between each code file and a corresponding associated test case;
[0207] The test case selection module 1203 is used to obtain the associated test cases corresponding to each modified code file according to the first corresponding relationship, and obtain a minimum valid test case collection consisting of all the associated test cases.
[0208] The test case acquisition device 1200 based on code file modification is described in detail below, as shown below:
[0209] In some embodiments, the above-mentioned test case acquisition device based on code file modification may further include:
[0210] Compilation module, used to compile all code files in the project and generate executable files;
[0211] The first coverage module is used to use the executable file to traverse and run each test case to be run in the complete test case collection to obtain the code coverage of each code file corresponding to the test case to be run;
[0212] The first comparison module is used to compare the code coverage of each code file corresponding to the test case to be run with the basic coverage of each code file, and select the code files with different code coverage and basic coverage as the code files associated with the test case to be run; wherein the basic coverage is the code coverage of each code file corresponding to the basic test case when the executable file runs the basic test case;
[0213] The first generating module is used to generate a first correspondence between code files and test cases according to all the test cases to be run and their associated code files.
[0214] In some embodiments, the above-mentioned test case acquisition device based on code file modification may further include:
[0215] The second coverage module is used to run the basic test case using the executable file, and generate the basic coverage of the basic test case corresponding to each code file according to the running result;
[0216] The second generating module is used to generate a basic code coverage relationship based on the basic coverage rate of each code file corresponding to the basic test case.
[0217] In some embodiments, the second coverage module may include:
[0218] The first running unit is used to run the basic test case using the executable file to obtain the code structure Gcno file and the coverage Gcda file corresponding to each code file;
[0219] A first conversion unit, used for converting a Gcno file and a Gcda file corresponding to each code file into a first Gcov file;
[0220] The first parsing unit is used to parse the first Gcov file corresponding to each code file to obtain the basic coverage of the basic test case corresponding to each code file.
[0221] In some embodiments, the above-mentioned test case acquisition device based on code file modification may further include:
[0222] The test case acquisition module is used to filter out test cases whose file names meet the preset filtering rules from the test case library according to the preset filtering rules to form a complete test case collection.
[0223] In some embodiments, the first comparison module may include:
[0224] The second running unit is used to obtain second Gcov files corresponding to each code file obtained after the executable file runs the test case to be run;
[0225] A second parsing unit is used to parse, for each code file, a second Gcov file corresponding to the code file to obtain a corresponding code coverage rate, and compare the code coverage rate with a basic coverage rate corresponding to the code file;
[0226] The CCM generation unit is used to generate mapping data between the code file and the test case to be run when the code coverage of the code file is different from the basic coverage, until the second Gcov files corresponding to all code files are traversed and parsed, and the first mapping relationship corresponding to the test case to be run is obtained according to the generated mapping data.
[0227] In some embodiments, the above-mentioned test case acquisition device based on code file modification may further include:
[0228] The second file determination module is used to obtain all test cases that have been modified in response to the modification submission instruction;
[0229] The test case adding module is used to add all the test cases that have been modified to the unmapped data table; wherein the minimum valid test case collection also includes all the test cases in the unmapped data table.
[0230] In some embodiments, the above-mentioned test case acquisition device based on code file modification may further include:
[0231] An update acquisition module is used to obtain the test cases to be updated from the unmapped data table;
[0232] An update association module is used to traverse and run each test case to be updated using an executable file, and determine the code files associated with the test case to be updated based on the code coverage of each code file corresponding to the test case to be updated and the basic coverage of each code file;
[0233] The updating module is used to update the first corresponding relationship and the unmapped data table based on each test case to be updated and the code file associated therewith.
[0234] In some embodiments, the update module may include:
[0235] A first deleting unit, configured to delete, for each test case to be updated, original mapping data corresponding to the test case to be updated in the first corresponding relationship;
[0236] An adding unit, used for adding the code file associated with the test case to be updated and the mapping data of the test case to be updated into a first corresponding relationship;
[0237] The second deleting unit is used to delete the test case to be updated from the unmapped data table.
[0238] In some embodiments, the update acquisition module may include:
[0239] An update acquisition unit, used for acquiring a test case in a first state from an unmapped data table as a test case to be updated;
[0240] The state changing unit is used to change the test case to be updated from the first state to the second state before the test case to be updated is run by using the executable file.
[0241] Figure 8 The hardware structure diagram of the test case acquisition device based on code file modification provided by an embodiment of the present invention is shown. The test case acquisition device based on code file modification can be at least one of a computer, a server, and a document generation dedicated device. The test case acquisition device based on code file modification includes a processor 1301 and a memory 1302 storing computer program instructions.
[0242] Specifically, the processor 1301 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiment of the present invention.
[0243] The memory 1302 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 1302 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 1302 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 1302 may be inside or outside a test case acquisition device modified based on a code file. In a particular embodiment, the memory 1302 is a non-volatile solid-state memory.
[0244] The memory 1302 may include a read-only memory (ROM), a flash memory device, a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory 1302 includes a tangible (non-transitory) computer-readable storage medium (e.g., a memory device) of one or more software that may be encoded with computer-executable instructions and that, when executed (e.g., by one or more processors), is operable to perform the operations described with reference to the methods according to the above aspects of the present disclosure.
[0245] The processor 1301 reads and executes the computer program instructions stored in the memory 1302 to implement any one of the test case acquisition methods based on code file modification in the above embodiments.
[0246] In one example, the test case acquisition device based on code file modification may further include a communication interface 1303 and a bus 1310. Figure 8 As shown, the processor 1301, the memory 1302, and the communication interface 1303 are connected via a bus 1310 and communicate with each other.
[0247] The communication interface 1303 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiment of the present invention.
[0248] Bus 1310 includes hardware, software or both, and couples the components of the test case acquisition device modified based on the code file to each other. For example, but not limitation, the bus may include an accelerated graphics port (AGP) or other graphics bus, an enhanced industrial standard architecture (EISA) bus, a front-side bus (FSB), a hypertransport (HT) interconnect, an industrial standard architecture (ISA) bus, an infinite bandwidth interconnect, a low pin count (LPC) bus, a memory bus, a microchannel architecture (MCA) bus, a peripheral component interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a serial advanced technology attachment (SATA) bus, a video electronics standard association local (VLB) bus or other suitable bus or a combination of two or more of these. Where appropriate, bus 1310 may include one or more buses. Although the embodiments of the present invention describe and illustrate a specific bus, the present invention contemplates any suitable bus or interconnect.
[0249] The test case acquisition device based on code file modification can be based on the test case acquisition method of code file modification, thereby realizing the combination of Figures 1 to 7 The described test case acquisition method and device based on code file modification.
[0250] In addition, in combination with the test case acquisition method based on code file modification in the above embodiment, the embodiment of the present invention can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the test case acquisition methods based on code file modification in the above embodiment is implemented.
[0251] In addition, an embodiment of the present invention further provides a computer program product, including a computer program, which can implement the steps and corresponding contents of the aforementioned method embodiment when executed by a processor.
[0252] In addition, the term "and / or" in this article is only a description of the association relationship between the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0253] It should be understood that in the embodiment of the present invention, "B corresponding to A" means that B is associated with A, and B can be determined according to A. However, it should also be understood that determining B according to A does not mean determining B only according to A, and B can also be determined according to A and / or other information.
[0254] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A test case acquisition method based on code file modification, characterized in that: include: In response to the modification submission instruction, all code files that have been modified are obtained; Obtaining a first corresponding relationship; wherein the first corresponding relationship includes mapping data between each code file and a corresponding associated test case; According to the first corresponding relationship, the associated test cases corresponding to each modified code file are respectively obtained to obtain a minimum valid test case collection consisting of all the associated test cases; Before obtaining all code files that have been modified in response to the modification submission instruction, the method further includes: Compile all code files in the project to generate executable files; Using the executable file to traverse and run each test case to be run in the complete test case collection, and obtain the code coverage rate of each code file corresponding to the test case to be run; Compare the code coverage of each code file corresponding to the test case to be run with the basic coverage of each code file, and select the code files with different code coverage and basic coverage as the code files associated with the test case to be run; wherein the basic coverage is the code coverage of each code file corresponding to the basic test case when the executable file runs the basic test case; According to all the test cases to be run and their associated code files, a first correspondence between the code files and the test cases is generated.
2. The test case acquisition method based on code file modification according to claim 1, characterized in that: Before using the executable file to traverse and run each test case to be run in the complete test case collection to obtain the code coverage of each code file corresponding to the test case to be run, the method further includes: Run the basic test case using the executable file, and generate the basic coverage of each code file corresponding to the basic test case according to the running result; A basic code coverage relationship is generated based on the basic coverage rate of each code file corresponding to the basic test case.
3. The test case acquisition method based on code file modification according to claim 2 is characterized in that: The step of running the basic test case using the executable file and generating the basic coverage of each code file corresponding to the basic test case according to the running result includes: Use the executable file to run the basic test case to obtain the code structure Gcno file and coverage Gcda file corresponding to each code file; Convert the Gcno file and Gcda file corresponding to each code file into the first Gcov file; Parse the first Gcov file corresponding to each code file to obtain the basic coverage of the basic test case corresponding to each code file.
4. The test case acquisition method based on code file modification according to claim 3 is characterized in that: The data type in the basic code coverage relationship is a key-value pair type, the key name includes the code file, and the key value includes the coverage rate.
5. The test case acquisition method based on code file modification according to claim 1, characterized in that: Before using the executable file to traverse and run each test case to be run in the complete test case collection, the method further includes: According to the preset screening rules, test cases whose file names meet the preset screening rules are screened out from the test case library to form a complete test case collection.
6. The test case acquisition method based on code file modification according to claim 1, characterized in that: The step of comparing the code coverage of each code file corresponding to the test case to be run with the basic coverage of each code file, and selecting code files with different code coverage and basic coverage as code files associated with the test case to be run, includes: Obtaining second Gcov files corresponding to the respective code files obtained after the executable file runs the test case to be run; For each code file, parse the second Gcov file corresponding to the code file to obtain the corresponding code coverage, and compare the code coverage with the basic coverage corresponding to the code file; When the code coverage of the code file is different from the basic coverage, mapping data between the code file and the test case to be run is generated until the second Gcov files corresponding to all code files are traversed and parsed, and the first mapping relationship corresponding to the test case to be run is obtained according to the generated mapping data.
7. The test case acquisition method based on code file modification according to claim 6, characterized in that: The first corresponding relationship includes a first mapping relationship corresponding to each test case to be run.
8. The test case acquisition method based on code file modification according to claim 1, characterized in that: The method further comprises: In response to the modification submission instruction, all test cases that have been modified are obtained; Add all the test cases that have been modified to the unmapped data table; wherein the minimum valid test case collection also includes all the test cases in the unmapped data table.
9. The test case acquisition method based on code file modification according to claim 8, characterized in that: After adding all the modified test cases to the unmapped data table, the method further includes: Acquire the test case to be updated from the unmapped data table; Utilize the executable file to traverse and run each test case to be updated, and determine the code file associated with the test case to be updated based on the code coverage of each code file corresponding to the test case to be updated and the basic coverage of each code file; Based on each test case to be updated and the code file associated therewith, the first corresponding relationship and the unmapped data table are updated.
10. The test case acquisition method based on code file modification according to claim 9, characterized in that: The updating of the first correspondence and the unmapped data table based on each test case to be updated and the code file associated therewith includes: For each test case to be updated, deleting the original mapping data corresponding to the test case to be updated in the first corresponding relationship; Adding the code file associated with the test case to be updated and the mapping data of the test case to be updated to the first corresponding relationship; The test case to be updated is deleted from the unmapped data table.
11. The test case acquisition method based on code file modification according to claim 9, characterized in that: The initial state of each test case in the unmapped data table is the first state; the obtaining the test case to be updated from the unmapped data table includes: Acquire a test case in a first state from the unmapped data table as a test case to be updated; Before using the executable file to run the test case to be updated, the test case to be updated is changed from a first state to a second state.
12. A test case acquisition device based on code file modification, characterized in that: include: A file determination module, for obtaining all code files that have been modified in response to a modification submission instruction; An acquisition module, configured to acquire a first corresponding relationship; wherein the first corresponding relationship includes mapping data between each code file and a corresponding associated test case; A test case selection module is used to obtain the associated test cases corresponding to each modified code file according to the first corresponding relationship, and obtain a minimum valid test case collection consisting of all the associated test cases; The test case acquisition device based on code file modification also includes: Compilation module, used to compile all code files in the project and generate executable files; The first coverage module is used to use the executable file to traverse and run each test case to be run in the complete test case collection to obtain the code coverage of each code file corresponding to the test case to be run; The first comparison module is used to compare the code coverage of each code file corresponding to the test case to be run with the basic coverage of each code file, and select the code files with different code coverage and basic coverage as the code files associated with the test case to be run; wherein the basic coverage is the code coverage of each code file corresponding to the basic test case when the executable file runs the basic test case; The first generating module is used to generate a first correspondence between code files and test cases according to all the test cases to be run and their associated code files.
13. A test case acquisition device based on code file modification, characterized in that: include: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the steps of the test case acquisition method based on code file modification as described in any one of claims 1 to 11 are implemented.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the steps of the test case acquisition method based on code file modification according to any one of claims 1 to 11 are implemented.
15. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor, the steps of the test case acquisition method based on code file modification according to any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Test case recommendation method and device, computer equipment and storage medium
CN110941555A
Incremental code coverage rate testing method and device, storage medium and electronic equipment
CN112799939A
