Incremental code coverage detection method and business development method and device
By analyzing and comparing the compiled files of the to-detect code, generating an incremental method list and marking it, the existing incremental code coverage detection problem is solved, and the incremental code coverage detection of the method dimension is realized, which improves the accuracy of the detection and the logical integrity of the coverage.
Patent Information
- Application Number
- CN202110645298.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-09
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-06-09
AI Technical Summary
The existing incremental code coverage detection method has a coarse granularity and cannot accurately locate the code block, resulting in the inability to effectively confirm whether all newly added or modified codes are covered, increasing the risk of online crashes.
By obtaining the first compiled file of the code to be detected and the second compiled file of the original code, the two are analyzed and compared, and an incremental method list is obtained. The first compiled file is marked based on the list, and a test installation package is generated for testing, and the incremental code coverage detection result is finally generated.
The method dimension incremental code coverage detection of code modification is realized, so that the modified code can be directly located to the dimension of the method. Compared with the dimension of positioning to the file or line, the difference comparison is more accurate and the coverage logic is more complete, reducing the risk of problem code going online.
Smart Images

Figure CN113282504B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to an incremental code coverage detection method and a business development method and device. Background Art
[0002] During the client project development process, the development code needs to be modified and the modified code needs to be self-tested and tested. However, the completeness of self-testing and testing: whether all new or modified codes are covered, referred to as incremental codes, cannot be effectively confirmed; when an iteration contains multiple requirements, unconfirmed code is merged into the branch of the current iteration of the code base, which will increase the risk of online crashes in the current iteration.
[0003] Currently, the existing incremental code coverage detection methods have a coarse detection granularity and usually detect from the full volume or file dimension, and cannot accurately locate the code block. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides an incremental code coverage detection method and a business development method and device to overcome the problem that the incremental code coverage detection method in the prior art has a coarse detection granularity and cannot accurately locate the code block.
[0005] An embodiment of the present invention provides an incremental code coverage detection method, comprising:
[0006] Obtaining a first compiled file of a code to be detected and a second compiled file of an original code corresponding to the code to be detected, wherein the code to be detected is a code modified from the original code;
[0007] Analyze and compare the first compiled file and the second compiled file to obtain an incremental method list, where the incremental method list is a set of methods that cause changes in the compiled files;
[0008] Marking the first compiled file based on the incremental method list, and generating a test installation package based on the marked first compiled file;
[0009] Testing the test installation package to obtain a test result;
[0010] An incremental code coverage detection result is generated based on the tag information included in the test result and the tag information corresponding to the incremental method list.
[0011] Optionally, marking the first compiled file based on the incremental method list includes:
[0012] The compilation content corresponding to each method in the incremental method list in the first compilation file is marked in sequence.
[0013] Optionally, generating an incremental code coverage detection result based on the tag information included in the test result and the tag information corresponding to the incremental method list includes:
[0014] Comparing the marking information included in the test result with the marking information corresponding to the incremental method list to determine the tested methods in the incremental method list;
[0015] Obtain a first compiled content of a first compiled file corresponding to the tested method and a second compiled content of the first compiled file corresponding to all methods in the incremental method list;
[0016] Extracting, from the code to be detected, a first source code line corresponding to the first compiled content and a second source code line corresponding to the second compiled content;
[0017] The incremental code coverage detection result is generated based on the line number relationship between the first source code line and the second source code line.
[0018] The embodiment of the present invention also provides a service development method, including:
[0019] Obtaining and compiling a business code, wherein the business code is a business code developed based on preset business requirements of the business to be developed;
[0020] The business code is tested using the incremental code coverage detection method according to another embodiment of the present invention to generate a corresponding incremental code coverage detection result;
[0021] Determine whether the incremental code coverage test result meets the preset test requirements;
[0022] When the incremental code coverage test result meets the preset test requirement, the business code that meets the preset business requirement is obtained.
[0023] Optionally, the method further comprises:
[0024] The business code that meets the preset business requirements is combined with the main code of the business to be developed and then integrated and tested;
[0025] After the integration test is passed, the product corresponding to the business to be developed is generated.
[0026] Optionally, when the incremental code coverage detection result does not meet the preset detection requirement, the incremental code coverage detection result is sent to the code development end so that the development personnel can confirm the business code;
[0027] Receive the confirmed business code, and return to the step of detecting the business code using the incremental code coverage detection method described in another embodiment of the present invention to generate a corresponding incremental code coverage detection result.
[0028] The embodiment of the present invention further provides an incremental code coverage detection device, comprising:
[0029] A first acquisition module is used to acquire a first compiled file of a code to be detected and a second compiled file of an original code corresponding to the code to be detected, wherein the code to be detected is a code modified from the original code;
[0030] A first processing module is used to analyze and compare the first compiled file and the second compiled file to obtain an incremental method list, where the incremental method list is a set of methods that cause changes in the compiled files;
[0031] a second processing module, configured to mark the first compiled file based on the incremental method list, and generate a test installation package based on the marked first compiled file;
[0032] A third processing module is used to test the test installation package and obtain a test result;
[0033] The fourth processing module is used to generate an incremental code coverage detection result based on the marking information included in the test result and the marking information corresponding to the incremental method list.
[0034] The embodiment of the present invention further provides a service development device, including:
[0035] A second acquisition module is used to acquire and compile a business code, wherein the business code is a business code developed based on a preset business requirement of the business to be developed;
[0036] A fifth processing module, configured to detect the service code using the incremental code coverage detection device according to another embodiment of the present invention, and generate a corresponding incremental code coverage detection result;
[0037] A sixth processing module, used to determine whether the incremental code coverage detection result meets the preset detection requirement;
[0038] The seventh processing module is used to obtain the business code that meets the preset business requirements when the incremental code coverage detection result meets the preset detection requirements.
[0039] An embodiment of the present invention further provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method provided by the embodiment of the present invention by executing the computer instructions.
[0040] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method provided by the embodiment of the present invention.
[0041] The technical solution of the present invention has the following advantages:
[0042] The embodiment of the present invention provides an incremental code coverage detection method and device, which obtains a first compiled file of the code to be detected and a second compiled file of the original code corresponding to the code to be detected; analyzes and compares the first compiled file and the second compiled file to obtain an incremental method list; marks the first compiled file based on the incremental method list, and generates a test installation package based on the marked first compiled file; tests the test installation package to obtain a test result; and generates an incremental code coverage detection result based on the marking information contained in the test result and the marking information corresponding to the incremental method list. Thus, by analyzing the compiled files before and after the code is modified, a set of methods that have been changed is obtained, and then by marking the changed methods in the compiled files, a test installation package is made using the marked compiled files for testing, so that the incremental code coverage of the code method dimension is obtained through the marking information of the test result, so that the modified code can be directly located to the method dimension, and the difference comparison is more accurate than the dimension located to the file, and the coverage logic is more complete than the dimension located to the line.
[0043] The embodiment of the present invention provides a business development method and device, including: obtaining business code and compiling it, the business code is a business code developed based on the preset business requirements of the business to be developed; using the incremental code coverage detection method of another embodiment of the present invention to detect the business code, and generate the corresponding incremental code coverage detection result; judging whether the incremental code coverage detection result meets the preset detection requirement; when the incremental code coverage detection result meets the preset detection requirement, the business code that meets the preset business requirement is obtained. Therefore, during the development process, the incremental code coverage detection method of another embodiment of the present invention is used for detection, and the coverage information is evaluated, which has a process checkpoint function, making the process of demand development and testing more objective, greatly reducing the risk of problem code (untested code) going online due to human problems, and eliminating the need for development and testing personnel to perform more manual operations, thereby realizing full-cycle automated development of the business. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 is a flow chart of an incremental code coverage detection method in an embodiment of the present invention;
[0046] Figure 2 A schematic diagram of an incremental method generation process in an embodiment of the present invention;
[0047] Figure 3 This is a specific application example diagram of incremental code coverage detection in an embodiment of the present invention;
[0048] Figure 4 is a flow chart of a service development method in an embodiment of the present invention;
[0049] Figure 5 An example diagram of a process of service development in an embodiment of the present invention;
[0050] Figure 6 It is a structural schematic diagram of an incremental code coverage detection device in an embodiment of the present invention;
[0051] Figure 7 A schematic diagram of the structure of a service development device in an embodiment of the present invention;
[0052] Figure 8 Schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0054] The technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0055] During the client project development process, the development code needs to be modified and the modified code needs to be self-tested and tested. However, the completeness of self-testing and testing: whether all new or modified codes are covered, referred to as incremental codes, cannot be effectively confirmed; when an iteration contains multiple requirements, unconfirmed code is merged into the branch of the current iteration of the code base, which will increase the risk of online crashes in the current iteration.
[0056] Currently, the existing incremental code coverage detection methods have a coarse detection granularity and usually detect from the full volume or file dimension, and cannot accurately locate the code block.
[0057] Based on the above problems, an embodiment of the present invention provides an incremental code coverage detection method, such as Figure 1 As shown, the method specifically comprises the following steps:
[0058] Step S101: obtaining a first compiled file of a code to be detected and a second compiled file of an original code corresponding to the code to be detected.
[0059] Among them, the code to be detected is the code modified from the original code. Specifically, the original code can be the initial code developed by the developer for a certain business development demand, or it can be the code that is improved and modified based on the initial code, and the code to be detected is the code that is added or modified on the basis of the original code. It should be noted that in the embodiment of the present invention, the use of the APS system, namely Advanced Planning and Scheduling, for business development is taken as an example, that is, the developers carry out business development through the APS system, which can manage the entire development process of the APP, integrating branch management, development process management, continuous integration and other functions. In actual applications, other development management systems can also be used for development management, and the present invention is not limited to this.
[0060] Step S102: Analyze and compare the first compiled file and the second compiled file to obtain an incremental method list, where the incremental method list is a set of methods that cause changes in the compiled files.
[0061] Among them, for application development using the APS system, the git command can be used to obtain the class files generated by git diff, including the initially constructed class files, i.e., the second compiled files, and the modified class files, i.e., the first compiled files. Then, tools with class file analysis functions such as asm are used to analyze the two class files to obtain the incremental method list. The asm used in the embodiment of the present invention is an ASM library, which is a code analysis and modification tool based on the Java bytecode level. ASM can directly generate binary class files, and can also dynamically modify class behavior before the class is loaded into the JVM.
[0062] For example, Figure 2 As shown, the specific implementation process of the above step S102 is as follows:
[0063] 1. Use the git diff command to preliminarily compare the changed class files (the initially built class files will be pushed to the branch: business branch name_base, and the latest built class files will be pushed to the branch: business branch name);
[0064] 2. Pull the difference class files of the two branches to two directories in the local workspace (business branch name_base and business branch name), load all class files in the two folders into asm, and analyze the class methods;
[0065] 3. Through the MethodVisitor of asm, the key information of each class method is spliced together, including but not limited to the current state of the method local variables and the operation stack member information, numerical type instructions, local variable type instructions, type instructions, domain operation instructions, method operation instructions, dynamic type instructions, comparison jump instructions, ldc instructions, local variable index increase instructions, jump instructions, query jump instructions, multi-dimensional array instructions, method try-catch blocks, local variable descriptions, operand stack maximum value and local variable table maximum value, etc. (Note: when executing the ldc instruction, the instruction indicates that int, float or String type constants are pushed from the constant pool to the top of the stack. Since the resource id information also belongs to the int constant, the resource id needs to be ignored when splicing the key information of the ldc instruction), and the message digest algorithm (Message-Digest Algorithm) is executed on the spliced key information string. It should be noted that in the embodiment of the present invention, MD5 is used as an example for explanation. In actual applications, other algorithms can also be used to compare methods, as long as the method differentiation comparison can be achieved. The present invention is not limited to this;
[0066] 4. Compare the MD5 results of all methods of the corresponding classes of the two branches. The difference in comparison is the incremental method set.
[0067] In summary, the incremental judgment of the embodiment of the present invention will fall into the dimension of code methods. Both modified methods and newly added methods are identified as incremental methods. In the process of executing incremental coverage, the incremental part will be covered and recorded, thereby realizing the detection of incremental code coverage in the method dimension.
[0068] Step S103: marking the first compiled file based on the incremental method list, and generating a test installation package based on the marked first compiled file.
[0069] Specifically, the compiled contents corresponding to each method in the incremental method list in the first compiled file are marked in turn. Exemplarily, jacoco (an open source coverage detection tool) can be used for insertion, and a client installation package after insertion can be generated, so that when the corresponding marked code is executed, the corresponding execution information can be stored locally on the device to determine whether the marked code is executed during the detection process. This incremental insertion method is also faster in packaging than the original full insertion method, which improves the overall business development efficiency. It should be noted that in actual applications, other coverage detection tools such as EMMA can also be used for marking, as long as the actual execution of the method code can be detected, and the present invention is not limited to this.
[0070] Step S104: Test the test installation package to obtain a test result.
[0071] Specifically, since the installation package is generated by the marked compiled file, the self-test or test required by the corresponding software development process is performed on it, and the execution information of the corresponding marked result will be included in the corresponding test result.
[0072] Step S105: Generate an incremental code coverage detection result based on the marking information included in the test result and the marking information corresponding to the incremental method list.
[0073] Specifically, in one embodiment, the above step S105 specifically includes the following steps:
[0074] Step S201: Compare the marking information included in the test result with the marking information corresponding to the incremental method list to determine the tested methods in the incremental method list.
[0075] Among them, since the marked method will contain the execution information of the corresponding marked result in the corresponding test result after testing, the corresponding marking information can be determined according to the corresponding execution information in the test result, and then the method that has been tested in the incremental method list can be determined.
[0076] Step S202: Obtain the first compilation content of the first compilation file corresponding to the tested method and the second compilation content of the first compilation file corresponding to all methods in the incremental method list.
[0077] In the compilation file, different methods correspond to different compilation contents. The first compilation content is the compilation content corresponding to the modified code that has been tested, and the second compilation content is the compilation content corresponding to all the modified codes.
[0078] Step S203: extracting a first source code line corresponding to the first compiled content and a second source code line corresponding to the second compiled content from the code to be detected.
[0079] The compiled content corresponding to each method is compiled from one or more lines of source code. Therefore, the number of lines of source code to be compiled can be determined in turn through the compiled content.
[0080] Step S204: Generate an incremental code coverage detection result based on the line number relationship between the first source code line and the second source code line.
[0081] Among them, incremental code coverage = executed code lines / total code lines, among which the total code lines are the sum of the code lines corresponding to the incremental (new or modified) methods, and the executed code lines are the executed code lines in the total code lines.
[0082] The following will describe in detail the incremental code coverage detection method provided by the embodiment of the present invention in conjunction with a specific application example. Figure 3 shown.
[0083] 1. Developers create business development branches through APS.
[0084] 2.APS calls the Jenkins service for initial building.
[0085] 3. During the initial build process, upload the initial build class files to the git repository.
[0086] 4. Developers perform business development on their own computers.
[0087] 5. The developer submits the developed code to the git repository.
[0088] 6. After submitting the code, the developer initiates the build of the corresponding branch from APS or Jenkins.
[0089] 7. During the build process, upload the compiled class files to the git repository.
[0090] 8. Use the git command to obtain the class files generated by git diff (initial build & modified build), and use asm locally to further analyze the two class files to obtain the incremental method list.
[0091] 9. According to the incremental method list generated in step 8, use jacoco to insert pins and generate the client installation package after insertion.
[0092] 10. Developers use the client installation package for self-testing or testing.
[0093] 11. On the mobile phone, an execution data ec file will be generated according to the test process. The file can be automatically uploaded or manually uploaded to the ec file service on the mobile phone.
[0094] 12.Jenkins executes the report generation task and pulls the ec file from the ec file service.
[0095] 13.Jenkins pulls the latest class files from the git class repository.
[0096] 14.Jenkins pulls the latest source code files from the git source repository.
[0097] 15.Jenkins generates a report based on ec files, class files, and source code files, and uploads the report to the report service.
[0098] 16. The user clicks the coverage data button of the corresponding branch to view the coverage data.
[0099] 17.APS responds to the user click and displays the report service or the corresponding coverage report to the user for viewing.
[0100] It can be seen from the above application examples that the incremental code coverage detection method of the embodiment of the present invention can directly locate the dimension of the method through the modified code. Compared with the dimension of the located file, the difference comparison is more accurate, and compared with the dimension of the located line, the coverage logic is more complete; and the overall interactive process is imperceptible to the development and test personnel, and is deeply embedded in the development and testing process. The development and test personnel do not need to perform more manual operations, and can view the corresponding code coverage information at the key nodes of each process.
[0101] By executing the above steps, the incremental code coverage detection method provided by the embodiment of the present invention obtains a set of changed methods by analyzing the compiled files before and after the code is modified, and then marks the changed methods in the compiled files, and uses the marked compiled files to create a test installation package for testing, so as to obtain the incremental code coverage of the code method dimension through the marking information of the test results, so that the modified code can be directly located in the method dimension. Compared with the dimension located in the file, the difference comparison is more accurate, and compared with the dimension located in the line, the coverage logic is more complete.
[0102] The embodiment of the present invention also provides a service development method, such as Figure 4 As shown, the business development method specifically includes the following steps:
[0103] Step S301: Obtain the business code and compile it.
[0104] The business code is a business code developed based on preset business requirements of the business to be developed. The business code may be the original source code or a source code added or modified based on the original source code, etc. The present invention is not limited thereto.
[0105] Step S302: Use the incremental code coverage detection method according to another embodiment of the present invention to detect the business code and generate corresponding incremental code coverage detection results.
[0106] When the business code is the initial source code, the corresponding original code is empty, that is, it is necessary to perform coverage detection on all codes in the original code to determine whether all codes are detected.
[0107] Step S303: Determine whether the incremental code coverage detection result meets the preset detection requirements.
[0108] Among them, the preset detection requirement is a preset coverage threshold. During the software development process, it is usually required that all modified codes need to be tested, that is, the final coverage is required to be 100%. If the coverage reaches 100%, it means that the business code meets the preset detection requirement. Of course, in actual applications, the preset coverage threshold can also be flexibly set according to the actual project development requirements, and the present invention is not limited to this.
[0109] Step S304: When the incremental code coverage detection result meets the preset detection requirement, a business code that meets the preset business requirement is obtained.
[0110] Among them, if the business code meets the preset detection requirements, it means that the business code has been qualified for development and can meet the corresponding business needs. It can be used for the next step of project development, such as: merging with the main code to generate the final APP.
[0111] Specifically, in one embodiment, the above-mentioned business development method further includes the following steps:
[0112] Step S305: When the incremental code coverage detection result does not meet the preset detection requirement, the incremental code coverage detection result is sent to the code development end so that the development personnel can confirm the business code.
[0113] Among them, if the coverage value in the incremental code coverage detection result is less than the preset threshold, the result will be sent to the R&D personnel for code confirmation, assisting the R&D personnel to accurately confirm the undetected code blocks, so as to promote the acceleration of the R&D process and ensure the security and effectiveness of the business code.
[0114] Step S306: Receive the confirmed service code and return to step S302.
[0115] Specifically, if the R&D personnel confirm the undetected code blocks, they can re-detect the confirmed business code. In actual applications, they can also continuously improve the test process according to the actual situation so that they can enter the next development and testing process normally.
[0116] Step S307: Merge the business code that meets the preset business requirements with the main code of the business to be developed and then conduct integration testing. The integration test after merging the business code with the main code is a comprehensive test before the product goes online. Only when the software product passes the integration test can it meet the conditions for going online.
[0117] Step S308: After the integration test is passed, the product corresponding to the business to be developed is generated.
[0118] The following will describe the service development method provided by the embodiment of the present invention in detail with reference to a specific application example. Figure 5 shown.
[0119] 1. Development and testing personnel can manage the life cycle of requirements through the APS system from the beginning to the end (review and launch). On this basis, they can establish relevant business process checkpoints in combination with the actual coverage report generation process.
[0120] 2. At each business checkpoint node, the APS system determines whether to enter the next development process based on the generated coverage data, thereby improving labor efficiency and reducing the involvement of development and testing personnel in the business development process.
[0121] 3. After the APS system determines that it fails, the developer can confirm the special scenario or the development test personnel can improve the self-test and test process so that they can enter the next development and test process normally.
[0122] Therefore, by analyzing the compiled class through asm, the incremental coverage can be directly located to the dimension of the modified method; and by combining the coverage with the business development test process management system, development and testing personnel can view the coverage information of each development and test node without performing any additional operations; the business development test process management system is based on coverage data and has a process checkpoint function, which objectively reduces the risk of problematic code going online.
[0123] By executing the above steps, the business development method provided by the embodiment of the present invention has a process checkpoint function by using the incremental code coverage detection method of another embodiment of the present invention to perform detection during the development process and evaluate the coverage information, so that the process of demand development and testing is more objective, which greatly reduces the risk of problematic code (untested code) going online due to human problems, and eliminates the need for development and testing personnel to perform more manual operations, thereby realizing full-cycle automated development of the business.
[0124] The embodiment of the present invention also provides an incremental code coverage detection device, such as Figure 6 As shown, the incremental code coverage detection device includes:
[0125] The first acquisition module 101 is used to acquire a first compiled file of the code to be detected and a second compiled file of the original code corresponding to the code to be detected, where the code to be detected is a modified code of the original code. For details, please refer to the relevant description of step S101 in the above method embodiment, which will not be repeated here.
[0126] The first processing module 102 is used to analyze and compare the first compiled file and the second compiled file to obtain an incremental method list, which is a set of methods that cause changes in the compiled files. For details, please refer to the relevant description of step S102 in the above method embodiment, which will not be repeated here.
[0127] The second processing module 103 is used to mark the first compiled file based on the incremental method list, and generate a test installation package based on the marked first compiled file. For details, please refer to the relevant description of step S103 in the above method embodiment, which will not be repeated here.
[0128] The third processing module 104 is used to test the test installation package and obtain the test result. For details, please refer to the relevant description of step S104 in the above method embodiment, which will not be repeated here.
[0129] The fourth processing module 105 is used to generate an incremental code coverage detection result based on the tag information contained in the test result and the tag information corresponding to the incremental method list. For details, please refer to the relevant description of step S105 in the above method embodiment, which will not be repeated here.
[0130] Through the collaborative cooperation of the above-mentioned components, the incremental code coverage detection device provided by the embodiment of the present invention obtains a set of changed methods by analyzing the compiled files before and after the code is modified, and then marks the changed methods in the compiled files, and uses the marked compiled files to create a test installation package for testing, so as to obtain the incremental code coverage of the code method dimension through the marking information of the test results, so that the modified code can be directly located in the method dimension. Compared with the dimension located in the file, the difference comparison is more accurate, and compared with the dimension located in the line, the coverage logic is more complete.
[0131] The embodiment of the present invention also provides a service development device, such as Figure 7 As shown, the business development device includes:
[0132] The second acquisition module 301 is used to acquire and compile the business code, which is a business code developed based on the preset business requirements of the business to be developed. For details, please refer to the relevant description of step S301 in the above method embodiment, which will not be repeated here.
[0133] The fifth processing module 302 is used to detect the business code using an incremental code coverage detection device as another embodiment of the present invention to generate a corresponding incremental code coverage detection result. For details, please refer to the relevant description of step S302 in the above method embodiment, which will not be repeated here.
[0134] The sixth processing module 303 is used to determine whether the incremental code coverage detection result meets the preset detection requirement. For details, please refer to the relevant description of step S303 in the above method embodiment, which will not be repeated here.
[0135] The seventh processing module 304 is used to obtain the business code that meets the preset business requirements when the incremental code coverage detection result meets the preset detection requirement. For details, please refer to the relevant description of step S304 in the above method embodiment, which will not be repeated here.
[0136] Through the collaborative cooperation of the above-mentioned components, the business development device provided by the embodiment of the present invention uses the incremental code coverage detection method of another embodiment of the present invention to perform detection during the development process and evaluates the coverage information, thereby having a process checkpoint function, making the demand development and testing process more objective, greatly reducing the risk of problematic code (untested code) going online due to human problems, and eliminating the need for development and testing personnel to perform more manual operations, thereby realizing full-cycle automated development of the business.
[0137] According to an embodiment of the present invention, there is also provided an electronic device, such as Figure 8As shown, the electronic device may include a processor 901 and a memory 902, wherein the processor 901 and the memory 902 may be connected via a bus or other means. Figure 8 The example of connecting through bus is taken in the following.
[0138] The processor 901 may be a central processing unit (CPU). The processor 901 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0139] The memory 902 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the methods in the method embodiments of the present invention. The processor 901 executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions and modules stored in the memory 902, that is, implementing the methods in the above method embodiments.
[0140] The memory 902 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required by at least one function; the data storage area may store data created by the processor 901, etc. In addition, the memory 902 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 902 may optionally include a memory remotely arranged relative to the processor 901, and these remote memories may be connected to the processor 901 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0141] One or more modules are stored in the memory 902 , and when executed by the processor 901 , the method in the above method embodiment is executed.
[0142] The specific details of the above electronic device can be understood by referring to the corresponding descriptions and effects in the above method embodiments, and will not be repeated here.
[0143] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0144] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. An incremental code coverage detection method, characterized in that: include: Obtaining a first compiled file of a code to be detected and a second compiled file of an original code corresponding to the code to be detected, wherein the code to be detected is a code modified from the original code; Analyze and compare the first compiled file and the second compiled file to obtain an incremental method list, where the incremental method list is a set of methods that cause changes in the compiled files; Marking the first compiled file based on the incremental method list, and generating a test installation package based on the marked first compiled file; Testing the test installation package to obtain a test result; An incremental code coverage detection result is generated based on the tag information included in the test result and the tag information corresponding to the incremental method list.
2. The method according to claim 1, characterized in that The marking the first compiled file based on the incremental method list includes: The compilation content corresponding to each method in the incremental method list in the first compilation file is marked in sequence.
3. The method according to claim 1, characterized in that The generating an incremental code coverage detection result based on the tag information included in the test result and the tag information corresponding to the incremental method list includes: Comparing the marking information included in the test result with the marking information corresponding to the incremental method list to determine the tested methods in the incremental method list; Obtain a first compiled content of a first compiled file corresponding to the tested method and a second compiled content of the first compiled file corresponding to all methods in the incremental method list; Extracting, from the code to be detected, a first source code line corresponding to the first compiled content and a second source code line corresponding to the second compiled content; The incremental code coverage detection result is generated based on the line number relationship between the first source code line and the second source code line.
4. A business development method, characterized in that: include: Obtaining and compiling a business code, wherein the business code is a business code developed based on preset business requirements of the business to be developed; Adopting the incremental code coverage detection method as described in any one of claims 1 to 3 to detect the business code, and generate corresponding incremental code coverage detection results; Determine whether the incremental code coverage test result meets the preset test requirements; When the incremental code coverage test result meets the preset test requirement, the business code that meets the preset business requirement is obtained.
5. The method according to claim 4, characterized in that Also includes: The business code that meets the preset business requirements is combined with the main code of the business to be developed and then integrated and tested; After the integration test is passed, the product corresponding to the business to be developed is generated.
6. The method according to claim 4, characterized in that When the incremental code coverage detection result does not meet the preset detection requirement, the incremental code coverage detection result is sent to the code development end so that the development personnel can confirm the business code; Receive the confirmed business code, and return to the step of detecting the business code using the incremental code coverage detection method as described in any one of claims 1 to 3 to generate a corresponding incremental code coverage detection result.
7. An incremental code coverage detection device, characterized in that: include: A first acquisition module is used to acquire a first compiled file of a code to be detected and a second compiled file of an original code corresponding to the code to be detected, wherein the code to be detected is a code modified from the original code; A first processing module is used to analyze and compare the first compiled file and the second compiled file to obtain an incremental method list, where the incremental method list is a set of methods that cause changes in the compiled files; a second processing module, configured to mark the first compiled file based on the incremental method list, and generate a test installation package based on the marked first compiled file; A third processing module is used to test the test installation package and obtain a test result; The fourth processing module is used to generate an incremental code coverage detection result based on the marking information included in the test result and the marking information corresponding to the incremental method list.
8. A business development device, characterized in that: include: A second acquisition module is used to acquire and compile a business code, wherein the business code is a business code developed based on a preset business requirement of the business to be developed; A fifth processing module, configured to detect the business code using the incremental code coverage detection device according to claim 7, and generate a corresponding incremental code coverage detection result; A sixth processing module, used to determine whether the incremental code coverage detection result meets the preset detection requirement; The seventh processing module is used to obtain the business code that meets the preset business requirements when the incremental code coverage detection result meets the preset detection requirements.
9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method according to any one of claims 1 to 6 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Efficient multi-system test code coverage rate management method
CN111061639A
Differential line code coverage rate enhancement marking method, system and device and storage medium
CN112612716A