Code coverage testing method, device, computer equipment and storage medium

By obtaining different versions of code from the code management platform during the system testing and regression testing stages, performing coverage tests and accumulating the results, the problem of code coverage data loss caused by server cache changes is solved and the accuracy of code coverage data is achieved. and integrity.

CN113946515BActive Publication Date: 2024-08-23青岛千奇网络技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111218106.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-19
Publication Date
2024-08-23
Estimated Expiration
2041-10-19

AI Technical Summary

Technical Problem

When the server cache service code is changed, the code coverage data will be cleared, resulting in inaccurate code coverage statistics and affecting the accuracy of the code coverage data.

Method used

During the system testing phase and regression testing phase, different versions of the code of the target service are obtained from the code management platform, code change coverage and full coverage testing are performed, and the test results are accumulated to generate a code testing report file to ensure the accuracy of the data.

Benefits of technology

By accumulating code change coverage and full coverage data, accurate code test reports are generated, which avoids the loss of coverage data during code deployment and ensures the accuracy and completeness of code coverage statistics.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113946515B
    Figure CN113946515B
Patent Text Reader

Abstract

The embodiment of the present application provides a code coverage test method, device, computer equipment and storage medium, which relates to the field of testing technology. The method includes: in the system testing stage, the code change coverage test task is performed on the code change lines and the first target code lines in each version of the code from the second version to the Mth version of the code, and M-1 first test results are obtained to determine the code change coverage of the Mth version of the code; in the regression testing stage, the code change lines and the second target code lines in each version of the code are respectively tested. The task of full code coverage is performed to obtain M-1 second test results to determine the cumulative value of full code coverage; a code test report file is generated according to the code change coverage and the cumulative value of full code coverage of the Mth version of the code. The use of this application can improve the accuracy of code coverage data. The present application relates to blockchain technology, such as writing the file described in the blockchain.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of testing technology, and in particular to a code coverage testing method, apparatus, computer equipment and storage medium. Background Art

[0002] At present, some tools are widely used in the market to perform code coverage testing. Generally speaking, you can monitor whether all the modified code has been executed by checking whether the coverage of the code modification line is 100%. In actual applications, in addition to focusing on whether all the modified lines are executed during the system testing phase, you also need to pay proper attention to whether all the code is executed during the regression testing phase. However, when the code of the service cached by the server changes, it is necessary to redeploy the new code of the service on the server. At this time, the code cached by the server for the service will be cleared, and at the same time, the code coverage data stored on the server will also be cleared. The previous test data causes the relevant indicators of the code coverage statistics to not meet the standards, affecting the accuracy of the code coverage data. Summary of the invention

[0003] The embodiments of the present application provide a code coverage testing method, apparatus, computer equipment, and storage medium, which can improve the accuracy of code coverage data.

[0004] In a first aspect, an embodiment of the present application provides a code coverage testing method, comprising:

[0005] In the system testing phase, the code of version 2 to version M of the target service is obtained from the code management platform respectively, and the task of testing the code change coverage is performed on at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results, where the first test results include the code change coverage; M is an integer greater than 2; the first target code line included in each version of the code refers to the unexecuted code change line determined from the at least one code change line included in the previous version of the code of each version;

[0006] Accumulating the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determining the cumulative code change coverage value as the code change coverage of the Mth version of the code;

[0007] In the regression testing phase, the task of testing the full coverage of the code is performed for at least one code change line included in each version of the code and at least one second target code line included in the code of each version, respectively, to obtain M-1 second test results, wherein the second test results include the full coverage of the code; the at least one second target code line included in the second version of the code refers to at least one unexecuted code line determined from the multiple code lines included in the first version of the code; the at least one second target code line included in each version of the code after the second version refers to at least one unexecuted code line determined from at least one code change line included in the previous version of the code of each version and at least one second target code line included in the previous version of the code of each version;

[0008] Accumulating the full code coverage rate included in each of the M-1 second test results to obtain a cumulative value of the full code coverage rate;

[0009] Generate a code test report file based on the code change coverage of the Mth version of the code and the cumulative value of the full code coverage.

[0010] Optionally, the method further includes:

[0011] According to the line information of the unexecuted code change lines included in the M-2th first test result, at least one unexecuted code change line is determined from at least one code change line included in the M-1th version of the code as at least one first target code line included in the Mth version of the code.

[0012] Optionally, the task of performing a test on the code change coverage of at least one code change line included in each version of the code from the second version to the Mth version of the code and at least one first target code line included in each version of the code includes:

[0013] Run the first test case to perform functional testing on at least one code change line included in each version of the code from the second version of the code to the Mth version of the code and at least one first target code line included in each version of the code, and call the code coverage statistics plug-in to count the code change coverage to obtain M-1 first test results.

[0014] Optionally, the method further includes:

[0015] Determine the function points corresponding to the first target code lines included in each version of the code;

[0016] Determining a first test scenario corresponding to the first target code line according to a correspondence between a function point and a test scenario and a function point corresponding to the first target code line;

[0017] When the set of test scenarios covered by the first test case does not include the first test scenario, it is determined that the first test case does not cover the first test scenario.

[0018] Optionally, the method further includes:

[0019] Based on the line information of the unexecuted code lines included in the M-2th second test result, at least one unexecuted code line is determined from at least one code change line included in the M-1th version of the code and at least one second target code line included in the M-1th version of the code to serve as the at least one second target line included in the Mth version of the code.

[0020] Optionally, the task of testing the full coverage of the code is performed on at least one code change line included in each version of the code and at least one second target code line included in each version of the code to obtain M-1 second test results, including:

[0021] Run the second test case to perform functional testing on at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and call the code coverage statistics plug-in to count the full code coverage to obtain M-1 second test results.

[0022] Optionally, the method further includes:

[0023] Determine the function points corresponding to the second target code lines included in each version of the code;

[0024] Determining a second test scenario corresponding to the second target code line according to a correspondence between a function point and a test scenario and a function point corresponding to the second target code line;

[0025] When the set of test scenarios covered by the second test case does not include the second test scenario, it is determined that the second test case does not cover the second test scenario.

[0026] In a second aspect, an embodiment of the present application provides a code coverage testing device, including:

[0027] A test module, used for obtaining, during a system test phase, the code of versions 2 to M of the target service from the code management platform, respectively, and performing a task of testing code change coverage on at least one code change line included in each version of the code from the versions 2 to M and at least one first target code line included in each version of the code, to obtain M-1 first test results, wherein the first test results include code change coverage; M is an integer greater than 2; the first target code line included in each version of the code refers to an unexecuted code change line determined from at least one code change line included in the previous version of the code of each version;

[0028] a processing module, configured to accumulate the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determine the cumulative code change coverage value as the code change coverage of the Mth version of the code;

[0029] The test module is further used to perform the task of testing the full coverage of the code for at least one code change line included in each version of the code and at least one second target code line included in each version of the code during the regression test phase, and obtain M-1 second test results, wherein the second test results include the full coverage of the code; the at least one second target code line included in the second version of the code refers to at least one unexecuted code line determined from the multiple code lines included in the first version of the code; the at least one second target code line included in each version of the code after the second version refers to at least one unexecuted code line determined from at least one code change line included in the previous version of the code and at least one second target code line included in the previous version of the code;

[0030] The processing module is further used to accumulate the full code coverage rate included in each of the M-1 second test results to obtain a cumulative value of the full code coverage rate;

[0031] The processing module is also used to generate a code test report file according to the code change coverage of the Mth version of the code and the cumulative value of the full code coverage.

[0032] In a third aspect, an embodiment of the present application provides a computer device, comprising a processor and a memory, wherein the processor and the memory are interconnected, wherein the memory is used to store computer program instructions, and the processor is configured to execute the program instructions to implement the method described in the first aspect.

[0033] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer program instructions are stored. When the computer program instructions are executed by a processor, they are used to execute the method described in the first aspect.

[0034] To summarize, during the system testing phase, the computer device can obtain the code of version 2 to version M of the target service from the code management platform respectively, and perform the task of testing the code change coverage for at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results; the computer device accumulates the code change coverage included in each first test result in the M-1 first test results to obtain a cumulative code change coverage value, and determines the cumulative code change coverage value as the code change coverage value of the M-th version of the code. ; During the regression testing phase, the computer device can perform the task of testing the full code coverage for at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and obtain M-1 second test results, where the second test results include the full code coverage; the computer device accumulates the full code coverage included in each second test result in the M-1 second test results to obtain a cumulative value of the full code coverage; the computer device generates a code test report file based on the code change coverage of the Mth version of the code and the cumulative value of the full code coverage. This process can improve the accuracy of the code coverage data. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0036] Figure 1 It is a flowchart of a code coverage testing method provided by an embodiment of the present application;

[0037] Figure 2 This is a flowchart of a code coverage testing method provided by yet another embodiment of the present application;

[0038] Figure 3 It is a flow chart of a code coverage testing device provided in an embodiment of the present application;

[0039] Figure 4It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0041] See also Figure 1 , is a flow chart of a code coverage testing method provided in an embodiment of the present application. The method can be applied to a computer device, which can be a smart terminal or a server. The method may include the following steps:

[0042] S101. During the system testing phase, the code of version 2 to version M of the target service is obtained from the code management platform respectively, and the task of testing the code change coverage is performed on at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results, where the first test results include the code change coverage.

[0043] For example, when M is 3, in the system testing phase, the computer device can obtain the second version of the code from the code management platform when the first time point is reached, and perform the task of testing the code change coverage on at least one code change line included in the second version of the code, to obtain the first first test result. Among them, at least one first target code included in the second version of the code is empty. In addition, the computer device can obtain the third version of the code from the code management platform when the second time point (after the first time point) is reached, and perform the task of testing the code change coverage on at least one code change line included in the third version of the code and at least one first target code line included in the third version of the code, to obtain the second first test result. Among them, at least one first target code line included in the third version of the code is at least one code change line that has not been executed determined from at least one code change line included in the second version of the code.

[0044] Wherein, the system test refers to combining the software that has undergone integration testing as a part of the computer system with other parts of the system, and conducting a series of rigorous and effective tests on the computer system in the actual operating environment to discover potential problems in the software, thereby ensuring the normal operation of the system. The code management platform refers to a platform for managing code, which can be an independent server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms, but is not limited to this. The target service may include a target application or a target microservice, etc. Wherein, M is an integer greater than 2. The first target code line included in each version of the code refers to the unexecuted code change line determined from at least one code change line included in the previous version of the code of each version. The code change line can also be called a change code line. Wherein, the at least one code change line included in each version of the code can be determined by comparing the code of the version with the code of the target version, such as the code of the first version. In one embodiment, the code of version 2 can be obtained after updating the code of version 1. The code of version M can be obtained after updating the code of version M-1. Or, each version of the code can be obtained after updating the code of the target version. The code change coverage refers to the ratio of executed code change lines determined based on at least one code change line included in the corresponding version of the code and at least one first target code line included in the corresponding version of the code.

[0045] In one embodiment, the first test result may also include line information of unexecuted code change lines, such as line numbers. The computer device may also determine at least one unexecuted code change line from at least one code change line included in the second version of the code as at least one first target code line included in the third version of the code based on the line information of the unexecuted code change line included in the first first test result. That is, the computer device may determine at least one code line corresponding to the line information of the unexecuted code change line included in the first first test result as at least one first target code line included in the third version of the code. The computer device may also determine at least one unexecuted code change line from at least one code change line included in the M-1th version of the code as at least one second target code line included in the Mth version of the code based on the line information of the unexecuted code change line included in the M-1th first test result. That is, the computer device may also use at least one code line corresponding to the line information of the unexecuted code change line included in the M-1th first test result as at least one second target code line included in the Mth version of the code.

[0046] In one embodiment, the computer device performs the task of testing the code change coverage of at least one code change line included in each version of the code from version 2 to version M of the code and at least one first target code line included in each version of the code by running a first test case on the computer device to perform functional testing on at least one code change line included in each version of the code from version 2 to version M of the code and at least one first target code line included in each version of the code, and calls a code coverage statistics plug-in to count the code change coverage to obtain M-1 first test results. The code coverage statistics plug-in may be, for example, a jacoco plug-in. The first test case may be one or more. In one embodiment, when there are multiple first test cases, each of the multiple first test cases corresponds to a different test scenario.

[0047] S102. Accumulate the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determine the cumulative code change coverage value as the code change coverage of the Mth version of the code.

[0048] For example, when M is 3, the computer device can accumulate the code change coverage included in the first test result and the code change coverage included in the second test result to obtain the accumulated code change coverage value as the code change coverage of the third version of the code. The accumulation of code change coverage makes it possible to achieve the purpose of code coverage data statistics for this version without repeatedly executing the corresponding test cases when the code is deployed.

[0049] S103. In the regression testing phase, the task of testing the full code coverage is performed for at least one code change line included in each version of the code and at least one second target code line included in each version of the code, to obtain M-1 second test results, where the second test results include the full code coverage.

[0050] For example, when M is 3, in the regression test phase, the computer device can perform the task of testing the full coverage of the code for the first version of the code and obtain the test result. After obtaining the test result, the computer device can perform the task of testing the full coverage of the code for at least one code change line included in the second version of the code and at least one second target code line included in the second version of the code, and obtain the first second test result. Among them, the at least one second target code line included in the second version of the code refers to at least one code line that is not executed determined from the multiple code lines included in the first version. After obtaining the first second test result, the computer device can perform the task of testing the full coverage of the code for at least one code change line included in the third version of the code and at least one second target code line included in the third version of the code, and obtain the second second test result. Among them, the at least one second target code line included in the third version of the code refers to at least one code change line that is not executed determined from at least one code change line included in the second version of the code and at least one second target code line included in the second version of the code.

[0051] Among them, regression testing refers to retesting with the new version of the code after modifying the old version of the code to confirm that the modification has not introduced new errors or caused errors in other codes. As can be seen from the above examples, the at least one second target code line included in the second version of the code refers to at least one unexecuted code line determined from the multiple code lines included in the first version of the code; the at least one second target code line included in each version of the code after the second version refers to at least one unexecuted code line determined from at least one code change line included in the previous version of the code and at least one second target code line included in the previous version of the code. Among them, the full code coverage refers to the proportion of executed code lines among the multiple code lines included in the first version of the code, or refers to the proportion of executed code lines determined based on at least one code change line and at least one second target code line included in the second version and each version after the second version.

[0052] In one embodiment, the second test result may also include line information of unexecuted code lines. The computer device may determine the at least one unexecuted code line as the at least one second target line included in the third version of the code from the at least one code change line included in the second version of the code and the at least one second target code line included in the second version of the code according to the line information of the at least one unexecuted code line included in the first second test result. That is, the computer device may determine the at least one code line corresponding to the line information of the at least one unexecuted code line included in the first second test result as the at least one second target code line included in the third version of the code. Accordingly, the computer device may also determine the at least one unexecuted code line as the at least one second target line included in the M-1 version of the code from the at least one code change line included in the M-1 version of the code according to the line information of the unexecuted code line included in the M-1 second test result. That is, the computer device may determine the at least one code line corresponding to the line information of the at least one unexecuted code line included in the M-1 second test result as the at least one second target code line included in the M-1 version of the code.

[0053] In one embodiment, the computer device performs the task of testing the full coverage of the code for at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and obtains M-1 second test results by running the second test case on the computer device to perform functional testing on at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and calling the code coverage statistics plug-in to count the full coverage of the code, and obtain M-1 second test results. In one embodiment, the second test case may include part of the first test case used in the system testing phase and a test case for testing all functions of the Mth version of the code.

[0054] S104. Accumulate the full code coverage rate included in each of the M-1 second test results to obtain a cumulative value of the full code coverage rate.

[0055] For example, when M is 3, the computer device can accumulate the full code coverage rate included in the first second test result and the full code coverage rate included in the second second test result to obtain the accumulated value of the full code coverage rate as the full code coverage rate of the third version of the code. The accumulation of the full code coverage rate makes it possible to achieve the statistical purpose of the code coverage rate data in this regression test phase without repeating the execution of the corresponding test cases when the code is deployed, and can solve the problem of code deployment test data loss.

[0056] S105. Generate a code test report file according to the code change coverage of the Mth version of the code and the cumulative value of the full code coverage.

[0057] That is to say, the computer device can generate a code test report file based on the cumulative value of the code change coverage and the cumulative value of the full code coverage. In one embodiment, the computer device can generate a first test report file based on the cumulative value of the code change coverage, and can also generate a second test file based on the cumulative value of the full code coverage. Separate coverage statistics in the system testing phase and the regression testing phase can determine in detail the version requirement use case coverage and regression use case coverage. For testers, the data in the report can be used to monitor the use case coverage and avoid missed tests in some scenarios. At the same time, it can also monitor whether developers have transferred the code privately.

[0058] visible, Figure 1 In the illustrated embodiment, during the system testing phase, the computer device may respectively obtain the code of version 2 to version M of the target service from the code management platform, and perform the task of testing the code change coverage on at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results, where the first test results include the code change coverage; the computer device accumulates the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determines the cumulative code change coverage value as the Mth version of the code. Code change coverage; in the regression testing phase, the computer device executes the task of testing the full code coverage of at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and obtains M-1 second test results, and the second test results include the full code coverage; the computer device can accumulate the full code coverage included in each second test result in the M-1 second test results to obtain the cumulative value of the full code coverage, and generate a code test report file according to the code change coverage and the cumulative value of the full code coverage of the Mth version of the code. By adopting this process, the accuracy of the code coverage statistical data can be guaranteed to the greatest extent.

[0059] See also Figure 2 , is a flowchart of a code coverage testing method provided by another embodiment of the present application. The method can be applied to the aforementioned computer device. Specifically, the method may include the following steps:

[0060] S201. During the system testing phase, the code of version 2 to version M of the target service is obtained from the code management platform respectively, and the task of testing the code change coverage is performed on at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results, where the first test results include the code change coverage.

[0061] S202. Accumulate the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determine the cumulative code change coverage value as the code change coverage of the Mth version of the code.

[0062] S203. In the regression testing phase, the task of testing the full code coverage is performed for at least one code change line included in each version of the code and at least one second target code line included in each version of the code, to obtain M-1 second test results, where the second test results include the full code coverage.

[0063] S204. Accumulate the full code coverage rate included in each of the M-1 second test results to obtain a cumulative value of the full code coverage rate.

[0064] S205. Generate a code test report file according to the code change coverage of the Mth version of the code and the cumulative value of the full code coverage.

[0065] Among them, steps S201 to S205 can be found in Figure 1 Steps S101 to S105 in the embodiment are not described in detail in the embodiment of the present application.

[0066] S206: Determine the function points corresponding to the first target code lines included in each version of the code.

[0067] S207: Determine a first test scenario corresponding to the first target code line according to the correspondence between the function point and the test scenario and the function point corresponding to the first target code line.

[0068] S208: When the set of test scenarios covered by the first test case does not include the first test scenario, determine that the first test case does not cover the first test scenario.

[0069] In step S206-step S208, the computer device may determine the function point corresponding to the first target code line included in each version of the code, and determine the first test scenario corresponding to the first target code line according to the correspondence between the function point and the test scenario and the function point corresponding to the first target code line; the computer device may determine that the first test case does not cover the first test scenario when the set of test scenarios covered by the first test case does not include the first test scenario. The first test scenario refers to the test scenario corresponding to the first target code line. In one embodiment, the computer device may determine the function point corresponding to the first target code included in each version of the code in the following manner: the computer device determines the code segment where the first target code line included in each version of the code is located; the computer device may determine the function tag information corresponding to the code segment where the first target code line included in each version of the code is located, and determine the function tag information corresponding to the code segment where the first target code line included in each version of the code is located as the function point corresponding to the first target code line included in each version of the code.

[0070] In one embodiment, the computer device may also determine the function point corresponding to the second target code line included in each version of the code, and determine the second test scenario corresponding to the second target code line based on the correspondence between the function point and the test scenario and the function point corresponding to the second target code line; when the set of test scenarios covered by the second test case does not include the second test scenario, the computer device may determine that the second test case does not cover the second test scenario. The second test scenario refers to the test scenario corresponding to the second target code line. In one embodiment, the computer device may determine the function point corresponding to the second target code included in each version of the code in the following manner: the computer device determines the code segment where the second target code line included in each version of the code is located; the computer device may determine the function tag information corresponding to the code segment where the second target code line included in each version of the code is located, and determine the function tag information corresponding to the code segment where the second target code line included in each version of the code is located as the function point corresponding to the second target code line included in each version of the code.

[0071] In one embodiment, the computer device can determine whether the cumulative value of the code change coverage is less than a first value. When the cumulative value of the code change coverage is less than the first value, the step of determining the function points corresponding to the first target code line included in each version of the code is triggered. In one embodiment, the computer device can determine whether the cumulative value of the full code coverage is less than a second value. When the cumulative value of the code change coverage is less than the second value, the step of determining the function points corresponding to the second target code line included in each version of the code is triggered. If the cumulative value of the code change coverage is low and the cumulative value of the full code coverage is low, it means that a lot of code has not been executed, that is, many scenarios are not covered. By determining the test scenarios that are not covered, it can be convenient for testers to test again.

[0072] In one embodiment, the computer device can obtain test cases that cover the first test scenario, and update the first test cases using the test cases that cover the first test scenario to obtain updated first test cases, and can run the updated first test cases during subsequent execution of the task of testing code change coverage. Correspondingly, the computer device can also obtain test cases that cover the second test scenario, and update the second test cases using the test cases that cover the second test scenario to obtain updated second test cases, and can run the updated second test cases during subsequent execution of the task of testing code change coverage. In one embodiment, the type of service tested by the test cases that cover the first test scenario is consistent with the type of the target service. The type of service tested by the test cases that cover the second test scenario is consistent with the type of the target service.

[0073] In one embodiment, the M-1th test result may include line information of unexecuted code change lines. The computer device determines the first code line set corresponding to the line information of the unexecuted code change lines included in the M-1th test result, and the first code line set includes at least one unexecuted code change line corresponding to the line information, and filters out the error code change line from the first code line set, and uses the error code change line as input data of the code generation model, and the code generation model generates a target number of virtual code change lines according to the error code change line as an optional correct code line. In one embodiment, the computer device can select a correct code line from the optional correct code lines to replace the error code change line, and then perform the task of testing the code change coverage on at least one code change line included in the M+1th version of the code, the selected correct code line, and the code lines in the first data set except the error code change line, to obtain the Mth first test result. In addition, the computer device can also perform the task of testing the full coverage of the code according to the selected correct code line and other code lines to obtain the Mth second test result.

[0074] In one embodiment, the computer device may send the first test scenario not covered by the first test case and / or the second test scenario not covered by the second test case to the user terminal corresponding to the tester. If the computer device receives confirmation information from the user terminal corresponding to the tester that the target test scenario in the first test scenario and / or the second test scenario has been tested, a modification confirmation message is sent to the user terminal corresponding to the developer, so that the user terminal corresponding to the developer confirms whether the code of the target service has been modified and not notified to the tester based on the modification confirmation information. The computer device receives the confirmation result returned by the user terminal corresponding to the developer, and forwards the confirmation result to the user terminal corresponding to the tester. The tester indicates that the corresponding test scenario has been tested, indicating that there is still code that has not been executed. Therefore, it may be because the development has modified the code without notifying the test, resulting in the modified code line not being covered. Therefore, the reason why the code line is not covered can be confirmed by the development.

[0075] When the existing technology uses code coverage statistics tools to count code coverage, if there is code deployment behavior, all coverage data will be cleared. Code deployment is a very common operation during the system testing phase. During the system testing phase, if there is no code change, the executed test cases will most likely not be executed repeatedly. Once there is a deployment behavior, the test data will also be cleared, and it will be impossible to accurately analyze the code coverage of the deployed code. Even in the regression testing phase, although you can pay appropriate attention to the code coverage of all codes, if there is code deployment behavior, all coverage data will be cleared, and it will also be impossible to accurately analyze the code coverage of the deployed code. For the above-mentioned situation that the relevant indicators of coverage statistics do not meet the standards, in the system testing phase, the present application can regularly pull the new version of the code from the code management platform, and determine the code change lines and the first target code lines included in the new version of the code, and then execute the test code change coverage task. After the execution is completed, the code change coverage of this time is automatically recorded. The next time the test code change coverage task is executed, the code change coverage of the previous time is automatically accumulated. In this way, after the last execution of the test code change coverage task, the cumulative value of the code change coverage can be obtained as the code coverage data statistics of this version. In the regression testing phase, the code is relatively stable. The present application can perform the task of testing the full coverage of the code after determining the code change lines and the second target code lines included in the new version of the code, automatically record the full coverage of this code, and automatically accumulate the full coverage of the code next time the task of testing the full change coverage of the code is executed. In this way, after the last execution of the task of testing the full coverage of the code, the cumulative value of the full coverage of the code can be obtained as the code coverage data statistics of the regression testing phase. The coverage statistics of the system testing phase and the regression testing phase can be carried out separately to determine the coverage of the version requirements and the coverage of the regression cases in detail. For testers, the data in the two reports can be used to monitor the coverage of use cases, avoid missing some scenarios, and also monitor whether developers have handed over code privately. Through the above method, the accuracy of code coverage statistics can be guaranteed to the greatest extent. According to the coverage test report, it is necessary to check again whether there are any missing scenarios and monitor the integrity of test scenarios and test cases.

[0076] The present application involves blockchain technology, such as writing a code test report file into a blockchain, or obtaining various versions of code through a blockchain network, or obtaining summary information of various versions of code through a blockchain, and then querying various versions of code from a code management platform based on the summary information.

[0077] visible, Figure 2In the illustrated embodiment, in addition to generating a code test report file based on the code change coverage rate of the Mth version of the code and the cumulative value of the full code coverage rate, the computer device can also determine the function points corresponding to the first target code lines included in each version of the code, and determine the first test scenario corresponding to the first target code line based on the correspondence between the function points and the test scenarios and the function points corresponding to the first target code lines. Thus, when the set of test scenarios covered by the first test case does not include the first test scenario, it is determined that the first test case does not cover the first test scenario. This process is used to quickly locate the problem that causes the unexecuted code, which can facilitate the testers to perform testing again, thereby improving the test efficiency.

[0078] See also Figure 3 , is a schematic diagram of the structure of a code coverage test device provided in an embodiment of the present application. The device can be applied to the aforementioned computer device. Specifically, the device may include:

[0079] The testing module 301 is used to obtain the code of version 2 to version M of the target service from the code management platform during the system testing phase, and perform the task of testing the code change coverage for at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results, where the first test results include the code change coverage; M is an integer greater than 2; the first target code line included in each version of the code refers to the unexecuted code change line determined from the at least one code change line included in the previous version of the code of each version.

[0080] The processing module 302 is used to accumulate the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determine the cumulative code change coverage value as the code change coverage of the Mth version of the code.

[0081] The testing module 301 is also used to perform the task of testing the full code coverage of at least one code change line included in each version of the code and at least one second target code line included in each version of the code during the regression testing phase, to obtain M-1 second test results, wherein the second test results include the full code coverage; the at least one second target code line included in the second version of the code refers to at least one unexecuted code line determined from the multiple code lines included in the first version of the code; the at least one second target code line included in each version of the code after the second version refers to at least one code change line included in the previous version of the code and at least one second target code line included in the previous version of the code.

[0082] The processing module 302 is further used to accumulate the full code coverage rate included in each of the M-1 second test results to obtain a cumulative value of the full code coverage rate.

[0083] The processing module 302 is further used to generate a code test report file according to the code change coverage of the Mth version of the code and the cumulative value of the full code coverage.

[0084] In an optional embodiment, the processing module 302 is further used to determine at least one unexecuted code change line from at least one code change line included in the M-1 version of the code as at least one first target code line included in the M version of the code based on the line information of the unexecuted code change line included in the M-2 first test result.

[0085] In an optional embodiment, the processing module 302 is also used to run the first test case to perform functional testing on at least one code change line included in each version of the code from the second version of the code to the Mth version of the code and at least one first target code line included in each version of the code, and call the code coverage statistics plug-in to count the code change coverage to obtain M-1 first test results.

[0086] In an optional embodiment, the processing module 302 is further used to determine the function point corresponding to the first target code line included in each version of the code; determine the first test scenario corresponding to the first target code line according to the correspondence between the function point and the test scenario and the function point corresponding to the first target code line; when the set of test scenarios covered by the first test case does not include the first test scenario, determine that the first test case does not cover the first test scenario.

[0087] In an optional embodiment, the processing module 302 is also used to determine at least one unexecuted code line from at least one code change line included in the M-1th version of the code and at least one second target code line included in the M-1th version of the code based on the line information of the unexecuted code lines included in the M-2th second test result, as the at least one second target line included in the Mth version of the code.

[0088] In an optional embodiment, the processing module 302 is also used to run a second test case to perform functional testing on at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and call the code coverage statistics plug-in to count the full code coverage to obtain M-1 second test results.

[0089] In an optional embodiment, the processing module 302 is further used to determine the function point corresponding to the second target code line included in each version of the code; determine the second test scenario corresponding to the second target code line according to the correspondence between the function point and the test scenario and the function point corresponding to the second target code line; when the set of test scenarios covered by the second test case does not include the second test scenario, determine that the second test case does not cover the second test scenario.

[0090] To summarize, the apparatus can obtain the code of version 2 to version M of the target service from the code management platform during the system testing phase, and perform the task of testing the code change coverage for at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results; the computer device accumulates the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determines the cumulative code change coverage value as the code change coverage value of the Mth version of the code. rate; the device can, during the regression testing phase, respectively perform the task of testing the full code coverage for at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and obtain M-1 second test results, where the second test results include the full code coverage; the device can accumulate the full code coverage included in each second test result in the M-1 second test results to obtain a cumulative value of the full code coverage; the computer device generates a code test report file based on the code change coverage and the cumulative value of the full code coverage of the Mth version of the code, and this process can improve the accuracy of the code coverage data.

[0091] See also Figure 4, is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device described in this embodiment may include: one or more processors 1000 and a memory 2000. The processor 1000 and the memory 2000 may be connected via a bus or the like.

[0092] The processor 1000 may be a central processing unit (CPU), or 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, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0093] The memory 2000 may be a high-speed RAM memory or a non-volatile memory, such as a disk memory. The memory 2000 is used to store a set of program codes, and the processor 1000 may call the program codes stored in the memory 2000. Specifically:

[0094] Processor 1000 is used to obtain, during a system testing phase, the code of versions 2 to M of the target service from the code management platform, and perform a task of testing code change coverage on at least one code change line included in each version of the code from the versions 2 to M and at least one first target code line included in each version of the code, to obtain M-1 first test results, wherein the first test results include code change coverage; M is an integer greater than 2; the first target code line included in each version of the code refers to an unexecuted code change line determined from at least one code change line included in the previous version of the code of each version; the code change coverage included in each of the M-1 first test results is accumulated to obtain a cumulative code change coverage value, and the cumulative code change coverage value is determined as the code change coverage of the Mth version of the code; during a regression testing phase, each version of the code is tested for code change coverage. The task of testing the full code coverage rate is performed based on at least one code change line included in the code and at least one second target code line included in each version of the code, to obtain M-1 second test results, wherein the second test results include the full code coverage rate; the at least one second target code line included in the second version of the code refers to at least one unexecuted code line determined from the multiple code lines included in the first version of the code; the code of each version after the second version includes at least one second target code line, which refers to at least one unexecuted code line determined from at least one code change line included in the previous version of the code of each version and at least one second target code line included in the previous version of the code of each version; the full code coverage rate included in each second test result in the M-1 second test results is accumulated to obtain a cumulative value of the full code coverage rate; a code test report file is generated according to the code change coverage rate of the Mth version of the code and the cumulative value of the full code coverage rate.

[0095] In one embodiment, the processor 1000 is further used to determine, based on the line information of the unexecuted code change line included in the M-2 first test result, at least one unexecuted code change line from at least one code change line included in the M-1 version of the code as at least one first target code line included in the M version of the code.

[0096] In one embodiment, the processor 1000 is specifically used to run a first test case to perform functional testing on at least one code change line included in each version of the code from the second version of the code to the Mth version of the code and at least one first target code line included in each version of the code, and call a code coverage statistics plug-in to count the code change coverage to obtain M-1 first test results.

[0097] In one embodiment, processor 1000 is further used to determine the function point corresponding to the first target code line included in each version of the code; determine the first test scenario corresponding to the first target code line according to the correspondence between the function point and the test scenario and the function point corresponding to the first target code line; when the set of test scenarios covered by the first test case does not include the first test scenario, determine that the first test case does not cover the first test scenario.

[0098] In one embodiment, the processor 1000 is further used to determine, based on the line information of the unexecuted code lines included in the M-2 second test result, at least one unexecuted code line from at least one code change line included in the M-1 version of the code and at least one second target code line included in the M-1 version of the code, as the at least one second target line included in the M version of the code.

[0099] In one embodiment, processor 1000 is also used to run a second test case to perform functional testing on at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and call a code coverage statistics plug-in to count the full code coverage to obtain M-1 second test results.

[0100] In one embodiment, processor 1000 is further used to determine the function point corresponding to the second target code line included in each version of the code; determine the second test scenario corresponding to the second target code line according to the correspondence between the function point and the test scenario and the function point corresponding to the second target code line; when the set of test scenarios covered by the second test case does not include the second test scenario, determine that the second test case does not cover the second test scenario.

[0101] In a specific implementation, the processor 1000 described in the embodiment of the present application may execute Figure 1 Example Figure 2 The implementation method described in the embodiment can also execute the implementation method described in the embodiment of the present application, which will not be repeated here.

[0102] Each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of sampling hardware or sampling software functional modules.

[0103] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed 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 computer-readable storage medium can be volatile or non-volatile. For example, the computer storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM). The computer-readable storage medium can mainly include a storage program area and a storage data area, wherein the storage program area can store an operating system, at least one application required for a function, etc.; the storage data area can store data created according to the use of the blockchain node, etc.

[0104] Among them, the blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.

[0105] What is disclosed above is only a preferred embodiment of the present application, and it certainly cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiment and equivalent changes made according to the claims of the present application are still within the scope covered by the present application.

Claims

1. A code coverage testing method, It is characterized in that include: In the system testing phase, the code of version 2 to version M of the target service is obtained from the code management platform respectively, and the task of testing the code change coverage is performed on at least one code change line included in each version of the code from version 2 to version M and at least one first target code line included in each version of the code, to obtain M-1 first test results, where the first test results include the code change coverage; M is an integer greater than 2; the first target code line included in each version of the code refers to the unexecuted code change line determined from the at least one code change line included in the previous version of the code of each version; Accumulating the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determining the cumulative code change coverage value as the code change coverage of the Mth version of the code; In the regression testing phase, the task of testing the full coverage of the code is performed on at least one code change line included in each version of the code and at least one second target code line included in the code of each version, respectively, to obtain M-1 second test results, wherein the second test results include the full coverage of the code; the at least one second target code line included in the second version of the code refers to at least one unexecuted code line determined from the multiple code lines included in the first version of the code; the at least one second target code line included in each version of the code after the second version refers to at least one unexecuted code line determined from at least one code change line included in the previous version of the code of each version and at least one second target code line included in the previous version of the code of each version; Accumulating the full code coverage rate included in each of the M-1 second test results to obtain a cumulative value of the full code coverage rate; Generate a code test report file based on the code change coverage of the Mth version of the code and the cumulative value of the full code coverage.

2. The method according to claim 1, It is characterized in that The method further comprises: According to the line information of the unexecuted code change lines included in the M-2th first test result, at least one unexecuted code change line is determined from at least one code change line included in the M-1th version of the code as at least one first target code line included in the Mth version of the code.

3. The method according to claim 1 or 2, It is characterized in that The task of testing the code change coverage of at least one code change line included in each version of the code from the second version to the Mth version of the code and at least one first target code line included in each version of the code includes: Run the first test case to perform functional testing on at least one code change line included in each version of the code from the second version of the code to the Mth version of the code and at least one first target code line included in each version of the code, and call the code coverage statistics plug-in to count the code change coverage to obtain M-1 first test results.

4. The method according to claim 3, It is characterized in that The method further comprises: Determine the function points corresponding to the first target code lines included in each version of the code; Determining a first test scenario corresponding to the first target code line according to a correspondence between a function point and a test scenario and a function point corresponding to the first target code line; When the set of test scenarios covered by the first test case does not include the first test scenario, it is determined that the first test case does not cover the first test scenario.

5. The method according to claim 1, It is characterized in that The method further comprises: Based on the line information of the unexecuted code lines included in the M-2th second test result, at least one unexecuted code line is determined from at least one code change line included in the M-1th version of the code and at least one second target code line included in the M-1th version of the code to serve as the at least one second target line included in the Mth version of the code.

6. The method according to claim 1 or 5, It is characterized in that The task of testing the full coverage of the code is performed on at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and M-1 second test results are obtained, including: Run the second test case to perform functional testing on at least one code change line included in each version of the code and at least one second target code line included in each version of the code, and call the code coverage statistics plug-in to count the full code coverage to obtain M-1 second test results.

7. The method according to claim 6, It is characterized in that The method further comprises: Determine the function points corresponding to the second target code lines included in each version of the code; Determining a second test scenario corresponding to the second target code line according to a correspondence between a function point and a test scenario and a function point corresponding to the second target code line; When the set of test scenarios covered by the second test case does not include the second test scenario, it is determined that the second test case does not cover the second test scenario.

8. A code coverage testing device, It is characterized in that include: A test module, used for obtaining, during a system test phase, the code of versions 2 to M of the target service from the code management platform, respectively, and performing a task of testing code change coverage on at least one code change line included in each version of the code from the versions 2 to M and at least one first target code line included in each version of the code, to obtain M-1 first test results, wherein the first test results include code change coverage; M is an integer greater than 2; the first target code line included in each version of the code refers to an unexecuted code change line determined from at least one code change line included in the previous version of the code of each version; a processing module, configured to accumulate the code change coverage included in each of the M-1 first test results to obtain a cumulative code change coverage value, and determine the cumulative code change coverage value as the code change coverage of the Mth version of the code; The test module is further used to perform the task of testing the full code coverage rate on at least one code change line included in each version of the code and at least one second target code line included in each version of the code during the regression test phase, and obtain M-1 second test results, wherein the second test results include the full code coverage rate; the at least one second target code line included in the second version of the code refers to at least one unexecuted code line determined from the multiple code lines included in the first version of the code; the at least one second target code line included in each version of the code after the second version refers to at least one unexecuted code line determined from at least one code change line included in the previous version of the code and at least one second target code line included in the previous version of the code; The processing module is further used to accumulate the full code coverage rate included in each of the M-1 second test results to obtain a cumulative value of the full code coverage rate; The processing module is also used to generate a code test report file according to the code change coverage of the Mth version of the code and the cumulative value of the full code coverage.

9. A computer device, It is characterized in that The method comprises a processor and a memory, wherein the processor and the memory are connected to each other, wherein the memory is used to store computer program instructions, and the processor is configured to execute the program instructions to implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, they are used to execute the method according to any one of claims 1 to 7.