Code coverage report generation method, device, equipment and medium
By receiving test requests, obtaining version identifiers, the deployment center performs code insertion and compression package operations, and using jacoco plug-in to generate code coverage reports, solving the problem of not being able to understand test coverage in the existing technology and improving the accuracy and efficiency of the test .
Patent Information
- Application Number
- CN202111264392.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-28
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2041-10-28
AI Technical Summary
Existing software testing technology cannot understand the classes and objects used by the test script in the system under test, as well as the coverage of the classes, methods and branches running in the system under test, resulting in unknown test ratios, which can easily lead to incomplete tests. Or it may not work well.
By receiving test requests, obtaining version identifiers, obtaining source code files from the code platform and pushing them to the deployment center, performing deployment and online code insertion, generating node overlay files and code compression packages, decompressing and merging class files, and generating code using jacoco plug-in tools Coverage report, automatically generate scientific code coverage reports.
It reduces the workload of manual code writing and testing, improves the accuracy and correctness of code coverage, and avoids the impact of compilation differences on the test effect.
Smart Images

Figure CN113986734B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of testing tools, and in particular to a method, device, equipment and medium for generating a code coverage report. Background Art
[0002] Software testing is an important part of the entire industry. It involves writing a series of test cases based on the understanding of functional requirements. However, current software testing can only obtain the results of the test script after it runs in the system under test, but cannot understand the classes and objects used by the test script in the system under test, as well as the coverage of the classes, methods, and branches of the test script running in the system under test. Therefore, the test ratio of the system under test is unknown, which can easily lead to incomplete coverage of the software test or poor test results. Summary of the invention
[0003] The present invention provides a code coverage report generation method, device, equipment and medium, which realizes the automatic generation of a reasonable and scientific code coverage report, reduces the workload of manual code writing and testing, improves the accuracy and correctness of code coverage, and ensures that the test effect is not affected by compilation differences.
[0004] A code coverage report generation method, comprising:
[0005] Receive a test request, and obtain a version identifier in the test request;
[0006] Obtaining a source code file corresponding to the version identifier from the code platform, and pushing the source code file to a deployment center;
[0007] Deployment based on the source code file is performed through the deployment center to obtain a deployment version associated with the version identifier and a plurality of microservices, and online code insertion and code packaging operations are performed on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices;
[0008] Decompress each of the code compression packages to obtain a class file corresponding to each of the microservices, and merge all of the node coverage files to obtain a total code coverage file;
[0009] A code coverage report is generated for the deployment version, the source code, all the class files and the total code coverage file through the jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier.
[0010] A code coverage report generating device, comprising:
[0011] A receiving module, used for receiving a test request and obtaining a version identifier in the test request;
[0012] A push module, used to obtain a source code file corresponding to the version identifier from a code platform, and push the source code file to a deployment center;
[0013] A packaging module, used to perform deployment based on the source code file through the deployment center, obtain a deployment version associated with the version identifier and multiple microservices, and perform online code insertion and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices;
[0014] A decompression module is used to decompress each of the code compression packages, obtain the class files corresponding to each of the microservices, and merge all the node coverage files to obtain a total code coverage file;
[0015] A generation module is used to generate a code coverage report for the deployment version, the source code, all the class files and the total code coverage file through a jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier.
[0016] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned code coverage report generating method when executing the computer program.
[0017] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned code coverage report generation method are implemented.
[0018] The code coverage report generation method, device, equipment and medium provided by the present invention receive a test request to obtain a version identifier in the test request; obtain a source code file corresponding to the version identifier from a code platform, and push the source code file to a deployment center; perform deployment based on the source code file through the deployment center to obtain a deployment version associated with the version identifier and multiple microservices, and perform online code insertion and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices; decompress each of the code compression packages to obtain a class file corresponding to each of the microservices, merge all the node coverage files to obtain a total code coverage file; and perform the deployment through the jacoco plug-in tool. The code coverage report is generated based on the version, the source code, all the class files and the total code coverage file to obtain a code coverage report corresponding to the version identifier. In this way, multiple microservices can be allocated through the deployment center, and the jacoco plug-in tool can be used to perform online code instrumentation and code packaging operations on each of the microservices to automatically obtain node coverage files and code compression packages, and finally automatically generate a code coverage report, thereby avoiding the situation where the compiled class files will have certain differences from the files deployed by the actual service due to differences in compilation tools, resulting in large errors in the output coverage, thereby reducing the workload of manual code writing and testing, greatly reducing costs, improving the accuracy and correctness of code coverage, and ensuring that the test effect is not affected by compilation differences. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0020] Figure 1 Schematic diagram of the application environment of the method for generating a code coverage report in one embodiment of the present invention;
[0021] Figure 2 is a flow chart of a method for generating a code coverage report in one embodiment of the present invention;
[0022] Figure 3 is a flowchart of step S30 of the method for generating a code coverage report in one embodiment of the present invention;
[0023] Figure 4 is a flowchart of step S30 of a method for generating a code coverage report in another embodiment of the present invention;
[0024] Figure 5is a principle block diagram of a code coverage report generating device in one embodiment of the present invention;
[0025] Figure 6 It is a principle block diagram of a packaging module of a code coverage report generating device in one embodiment of the present invention;
[0026] Figure 7 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions 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 ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0028] The code coverage report generation method provided by the present invention can be applied in Figure 1 In an application environment, a client (computer device or terminal) communicates with a server through a network. The client (computer device or terminal) includes, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server can be an independent server 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 (CDNs), and big data and artificial intelligence platforms.
[0029] In one embodiment, if Figure 2 As shown, a method for generating a code coverage report is provided, and its technical solution mainly includes the following steps S10-S50:
[0030] S10, receiving a test request, and obtaining a version identifier in the test request.
[0031] Understandably, the test request is a request triggered when the source code file to be tested corresponding to the version identifier needs to be tested and a code coverage report needs to be output, and the version identifier is a unique identifier assigned to the source code.
[0032] S20, obtaining a source code file corresponding to the version identifier from a code platform, and pushing the source code file to a deployment center.
[0033] It can be understood that the code platform stores all source code files, one source code file corresponds to one version identifier, the source code file corresponding to the version identifier is queried from the code platform, and the source code file is pushed to the deployment center through the webhook interface. The webhook interface is an interface for sending or receiving information using the webhook mechanism. The webhook mechanism is an assembly script pre-written for the A side, and then provides a network address for the webhook interface. Every time the B side creates new data, it will request the network address of the A side. The A side processes the data after receiving the request from the B side.
[0034] Among them, the webhook interface is called a reverse API (application programming interface), that is, the front end does not actively send requests, but is completely pushed by the back end.
[0035] S30, performing deployment based on the source code file through the deployment center, obtaining a deployment version associated with the version identifier and multiple microservices, and performing online code insertion and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices.
[0036] It can be understood that the deployment center is a center for managing all node servers or microservices. The deployment center can deploy multiple microservices and provide different services based on microservices. The deployment process based on the source code file is a process in which the deployment center generates a deployment version corresponding to the version identifier, and based on a resource optimization mechanism, allocates the microservices associated with the deployment version, pushes the source code to each microservice, and enables each microservice to compile the received source code.
[0037] Among them, the process of online code instrumentation is to install the jacoco plug-in tool for the deployed microservice, that is, to push the data packet of the jacoco plug-in tool automatically installed to each microservice, complete the installation of the jacoco plug-in tool in each microservice, use the jacoco plug-in tool in each microservice to perform a code dump operation on the source code in each microservice, and output the node coverage file corresponding to each microservice. The process of code packaging operation is the process of overall packaging of the compiled source code in the microservice. The dump operation can be to first automatically scan the location of the jacoco plug-in tool and the port of the microservice, and then export the exec file and configuration operation according to the source code.
[0038] In one embodiment, if Figure 3As shown, in the step S30, that is, the deployment based on the source code file is performed by the deployment center to obtain a deployment version associated with the version identifier and a plurality of microservices, including:
[0039] S301, generating a deployment version corresponding to the version identifier through the deployment center, and obtaining the deployment version through a webhook interface.
[0040] It can be understood that the process of generating a deployment version corresponding to the version identifier is a process of converting the current time, the version identifier, the number of files in the source code file and the check code into a digital or alphabetic format, and concatenating the resulting version in the order of time, the version identifier, the number of files and the check code, and determining the version as the deployment version corresponding to the version identifier.
[0041] S302: Based on a resource optimization mechanism, the microservice associated with the deployment version is allocated through the deployment center.
[0042] Understandably, the resource optimization mechanism is to find out the microservice that is most similar to the deployment version to be deployed from the current deployment list in the deployment center, so that the installation operation of the microservice can be reduced, and only the different plug-ins need to be installed.
[0043] Among them, the current deployment list records the collection of all currently online services or microservices to be served. The deployment list includes the historical deployment version, the port, IP address and microservice name of the microservice. The historical deployment version is the version generated historically for the historical source code. The port of the microservice is also called the PORT of the microservice. The IP address of the microservice is the unique address of the microservice on the Internet, and the microservice name is the computer name of the microservice.
[0044] In one embodiment, the step S302, i.e., allocating the microservice associated with the deployment version through the deployment center based on the resource optimization mechanism, includes:
[0045] The current deployment list is read through the deployment center, and the historical source code corresponding to the historical deployment version in the current deployment list is obtained.
[0046] It can be understood that the deployment center stores all the historical source codes, which are source codes that have been deployed in the deployment center in the past. One historical deployment version corresponds to one historical source code, and the historical source code corresponding to the historical deployment version corresponding to each microservice in the current deployment list is searched from the deployment center.
[0047] The deployment center compares the source code with the acquired historical source codes to obtain a repetition rate corresponding to each historical source code.
[0048] Understandably, the code compare-based comparison tool in the deployment center is used to compare the duplication of directories and codes between the source code and the acquired historical source codes, and determine the duplication rate corresponding to each historical source code.
[0049] The historical microservices associated with the historical deployment version corresponding to the historical source code corresponding to the maximum repetition rate are queried.
[0050] Understandably, the maximum repetition rate with the largest value is obtained from all the repetition rates, the historical source code corresponding to the maximum repetition rate is queried, and the historical microservice that was once associated with the historical deployment version is determined based on the historical deployment version corresponding to the historical source code.
[0051] The historical microservice is a microservice that has been deployed in the past.
[0052] The queried historical microservice is recorded as a microservice associated with the deployment version.
[0053] Understandably, the queried historical microservice is associated with the deployment version.
[0054] The present invention realizes reading the current deployment list through the deployment center, and obtaining the historical source code corresponding to the historical deployment version in the current deployment list; comparing the source code with each of the historical source codes obtained by the deployment center to obtain the repetition rate corresponding to each of the historical source codes; querying the historical microservice associated with the historical deployment version corresponding to the historical source code corresponding to the maximum repetition rate; recording the queried historical microservice as the microservice associated with the deployment version, so that the deployment center compares the source code with each of the historical source codes associated in the current deployment list, and the historical microservice corresponding to the maximum repetition rate is recorded as the microservice required to be deployed associated with the deployment version, without manual deployment, thereby improving the efficiency of code coverage testing.
[0055] S303: Push the source code to the assigned microservices, and instruct each microservice to compile according to the received source code.
[0056] It can be understood that the source code is pushed to the microservices associated with the deployment version. After receiving the source code, each microservice triggers a script to compile the source code by itself, that is, a self-compiled script file is attached to the source code file. When the script file is stored in a new storage location, it detects that the address of the storage location has changed, and automatically triggers the compilation action of the source code.
[0057] The source code compilation process is a Java code compilation process, which refers to the process of analyzing the input source code through the compiler, entering it into the symbol table, annotating it, and finally performing semantic analysis and generating a class file.
[0058] S304: Detect that each of the microservices returns a compiled completion instruction, and determine that the deployment of each of the microservices is complete.
[0059] It can be understood that after the compilation of each of the microservices is completed, the completion instruction of each of the microservices is triggered. The completion instruction reflects the instruction for the microservice to complete the compilation and send after generating the class file in combination with its own configuration. After detecting that each microservice associated with the deployment version returns the corresponding completion instruction, it is determined that the deployment of the microservice associated with the deployment version is completed.
[0060] The present invention realizes generating a deployment version corresponding to the version identifier through the deployment center, and obtaining the deployment version through a webhook interface; based on a resource optimization mechanism, allocating the microservices associated with the deployment version through the deployment center; pushing the source code to the allocated microservices, and instructing each of the microservices to compile according to the received source code; detecting that each of the microservices returns a compiled completion instruction, and determining that the deployment of each of the microservices is completed, so that the optimal microservices are allocated through the resource optimization mechanism, and instructing each of them to compile the source code, and automatically compiling and completing the deployment of the service corresponding to the source code.
[0061] In one embodiment, if Figure 4 As shown, in step S30, that is, performing online code plugging and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices, includes:
[0062] S31, installing the jacoco plug-in tool on the deployed microservice.
[0063] Understandably, an installation package corresponding to the jacoco plug-in tool is sent to each deployed microservice, and an instruction to install the installation package is triggered after the installation package is sent, thereby installing the jacoco plug-in tool into the deployed microservice.
[0064] S32, performing a code dump operation on each of the microservices through a jacoco plug-in tool installed in each of the microservices to obtain a node coverage file corresponding to each of the microservices.
[0065] Understandably, the dump operation is to stop the jvm (Java Virtual Machine, Java virtual machine, memory stored in the microservice) in the microservice after the microservice runs the source code, and to perform plugging by executing the ant file, thereby outputting the exec file after execution. The exec file is used as the process of the node coverage file. In this process, plugging can be performed by On-the-fly plugging, that is, in the jvm, a specific jar file is specified by the javaagent parameter to start the Instrumentation agent. The agent determines whether to convert and modify the class file (that is, the class file in java) before loading a class through the Class Loader, and inserts the statistical code into the class to complete the test coverage.
[0066] The stub processing is to traverse all class files and modify the qualified methods therein, and inject the code of the monitoring method of the object involved in the call. The ant file is the file output by compiling the source code, and the exec file is an executable Java file with the extension exec.
[0067] S33, performing code packaging operations on each of the microservices through the jacoco plug-in tool installed in each of the microservices to obtain a code compression package corresponding to each of the microservices.
[0068] It can be understood that the code packaging is a process in which, after the microservice compiles the received source code, it combines the file structure in the microservice to generate a class file suitable for the microservice, i.e., a class file, and compresses the class file and the compiled source code to package them into a code compression package.
[0069] The present invention realizes the installation of a jacoco plug-in tool on the deployed microservices; performing a code dump operation on each microservice through the jacoco plug-in tool installed in each microservice to obtain a node coverage file corresponding to each microservice; performing a code packaging operation on each microservice through the jacoco plug-in tool installed in each microservice to obtain a code compression package corresponding to each microservice. In this way, the dump operation can be performed through the jacoco plug-in tool to automatically complete the output of the node coverage file of each microservice, and the compiled source code can be automatically packaged without manual operation and code writing of code coverage test cases, thereby improving the efficiency and accuracy of code coverage.
[0070] S40, decompress each of the code compression packages to obtain a class file corresponding to each of the microservices, merge all of the node coverage files to obtain a total code coverage file.
[0071] It can be understood that the decompression is the reverse process of the code packaging, and it is a process of obtaining the class files corresponding to each of the microservices from the decompressed code compression package. The reason for obtaining the class files is that due to the differences in compilation tools, the compiled class files will be somewhat different from the files actually deployed by the service, which will cause a large error in the subsequent output coverage. In order to ensure the accuracy of the coverage data, it is necessary to pull the class files deployed by the service online. The merging process is the process of merging all the node coverage files using the merge method to obtain the total code coverage file.
[0072] S50, generating a code coverage report for the deployment version, the source code, all the class files and the total code coverage file through the jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier.
[0073] It can be understood that the process of generating the code coverage report is to use the jacoco plug-in tool to merge and deduplicate all the class files to obtain a total class file, and color-mark each line in the source code based on the total code coverage file to obtain the marked source code, and perform statistics on the proportion of tested lines of the marked code lines to calculate the instrumentation coverage rate; associate the deployment version, the total class file, the marked source code and the instrumentation coverage rate with each other, and then fill them in according to the preset report format, thereby generating the code coverage report.
[0074] The present invention realizes receiving a test request and obtaining a version identifier in the test request; obtaining a source code file corresponding to the version identifier from a code platform and pushing the source code file to a deployment center; performing deployment based on the source code file through the deployment center to obtain a deployment version associated with the version identifier and a plurality of microservices, and performing online code plugging and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices; decompressing each of the code compression packages to obtain a class file corresponding to each of the microservices, merging all of the node coverage files to obtain a total code coverage file; and performing online code plugging and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices. This method generates a code coverage report for the source code, all the class files and the total code coverage file, and obtains a code coverage report corresponding to the version identifier. In this way, multiple microservices can be allocated through the deployment center, and the jacoco plug-in tool can be used to perform online code instrumentation and code packaging operations on each of the microservices to automatically obtain node coverage files and code compression packages, and finally automatically generate a code coverage report, thereby avoiding the situation where the compiled class files will have certain differences from the files deployed by the actual service due to differences in compilation tools, resulting in large errors in the output coverage rate, thereby improving the accuracy of the code coverage rate, reducing the workload of manual code writing and testing, and greatly reducing costs.
[0075] In one embodiment, in step S50, that is, generating a code coverage report for the deployment version, the source code, all the class files and the total code coverage file through the jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier includes:
[0076] S501, merging and deduplicating all the class files to obtain a total class file.
[0077] Understandably, the contents of all the class files are merged and the duplicate contents are deduplicated to obtain the total class file, which embodies the class files that can meet the requirements of all microservice operation services.
[0078] S502: According to the total code coverage file, color-mark and count each line in the source code to obtain marked source code and instrumentation coverage.
[0079] It can be understood that the color marking is a process of marking by using red, yellow and green to represent the relationship between uninstrumented tests, associated instrumented tests and instrumented tests respectively. According to the total code coverage file, the color marking is performed on each line in the source code to obtain the marked source code, and then the proportion of red, yellow and green in the marked source code is calculated for the marked source code, so as to obtain the instrumentation coverage rate of the distribution of the three colors.
[0080] The step S501 and the step S502 may be executed in parallel or in series, in no particular order, and are not limited here.
[0081] S503: Associating the deployment version, the general class file, the marked source code, and the instrumentation coverage rate with each other, and generating the code coverage report.
[0082] It can be understood that the deployment version, the general class file, the marked source code and the instrumentation coverage are associated with each other, and the deployment version, the general class file, the marked source code and the instrumentation coverage are filled in the corresponding positions of the preset template respectively, so as to generate the code coverage report.
[0083] The present invention realizes the process of merging all the class files for deduplication to obtain a total class file; color-marking and counting each line in the source code according to the total code coverage file to obtain the marked source code and the instrumentation coverage rate; associating the deployment version, the total class file, the marked source code and the instrumentation coverage rate with each other, and generating the code coverage report. In this way, by merging deduplication processing and color marking, the code coverage report can be generated more accurately, scientifically and intuitively.
[0084] In one embodiment, after step S50, that is, after obtaining the code coverage report corresponding to the version identifier, the following steps are included:
[0085] S60: Receive an access request, and obtain a target version identifier in the access request.
[0086] Understandably, the access request is received through the nginx proxy interface, and the access request is a request for obtaining a code coverage report corresponding to a target version identifier, and the target version identifier is a unique version identifier of the code coverage report that needs to be viewed.
[0087] Among them, the nginx proxy interface is an interface that can use forward proxy, reverse proxy and transparent proxy for proxy. For example, if the nginx proxy interface is set to a forward proxy, the access request is received in the form of a forward proxy. The forward proxy is a server located between the client and the origin server. In order to obtain content from the origin server, a request is sent to the proxy server and the target is specified. Then the proxy server forwards the request to the server and returns the obtained content to the client.
[0088] S70, querying a code coverage report corresponding to the target version identifier, and performing test uncovered extraction on the found code coverage report to obtain a plurality of untested code lines.
[0089] It can be understood that the code coverage report corresponding to the target version identifier is queried from the code coverage report database, and the code coverage report database stores code coverage reports corresponding to all version identifiers. The process of extracting the test uncovered is the process of extracting the code lines of color identified as corresponding to the uninstrumented test from the code coverage report after finding the code coverage report corresponding to the target version identifier, and recording the extracted code lines of color identified as corresponding to the uninstrumented test as the untested code lines.
[0090] S80, generating test cases according to all the untested code lines to obtain test recommended cases.
[0091] It can be understood that the process of test case generation is to perform code decomposition based on the untested code, distinguish and identify the decomposed entities, thereby generating unit cases for the identified entities, and merging the generated unit cases to obtain the test recommended cases. The test recommended cases are cases generated using the test case generation method.
[0092] In one embodiment, the step S80, i.e., generating test cases according to all the untested code lines to obtain test recommended cases, includes:
[0093] Code decomposition is performed on each of the untested codes to decompose code entities.
[0094] Understandably, the code decomposition is to identify the statement type of the untested code, extract code entities other than the regular code statements corresponding to the statement type from the untested code according to the identified statement type, and associate the statement type with each of the extracted code entities.
[0095] Unit use cases are generated for each of the code entities to obtain unit use cases corresponding to each of the code entities.
[0096] It can be understood that according to the statement type associated with each code entity, the use case template corresponding to each statement type is obtained from the use case template library, and each code entity is filled into the corresponding use case template, so as to obtain the unit use case corresponding to each code entity one by one.
[0097] All the unit use cases are merged to obtain the test recommended use cases.
[0098] Understandably, all the unit use cases are summarized and merged into one test recommendation use case.
[0099] The present invention realizes code decomposition of each of the untested codes to decompose code entities; unit case generation for each of the code entities to obtain unit cases corresponding to each of the code entities; and merging all of the unit cases to obtain the test recommended cases. In this way, unit cases corresponding to the code entities can be automatically generated based on statement types, thereby automatically generating test recommended cases, reducing the workload of manually writing cases and improving the efficiency of case generation.
[0100] S90, returning the recommended test case and the found code coverage report to the terminal corresponding to the access request.
[0101] Understandably, the recommended test cases and the code coverage report are returned together to the terminal corresponding to the access request, so that the user can optimize the source code according to the recommended test cases and the code coverage report.
[0102] The present invention achieves the following results: after obtaining multiple code coverage reports, an access request is received to obtain a target version identifier in the access request; the code coverage report corresponding to the target version identifier is queried, and test uncovered extraction is performed on the found code coverage report to obtain multiple untested code lines; test case generation is performed based on all the untested code lines to obtain test recommended cases; the test recommended cases and the found code coverage report are returned to the terminal corresponding to the access request. In this way, test case generation for untested code can be automatically performed to provide test recommended cases without the need for manual test case writing, thereby improving the efficiency of code coverage testing.
[0103] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0104] In one embodiment, a code coverage report generation device is provided, and the code coverage report generation device corresponds one-to-one to the code coverage report generation method in the above embodiment. Figure 5As shown, the code coverage report generating device includes a receiving module 11, a pushing module 12, a packaging module 13, a decompression module 14 and a generating module 15. The detailed description of each functional module is as follows:
[0105] The receiving module 11 is used to receive a test request and obtain a version identifier in the test request;
[0106] A push module 12, used to obtain a source code file corresponding to the version identifier from a code platform, and push the source code file to a deployment center;
[0107] The packaging module 13 is used to perform deployment based on the source code file through the deployment center, obtain the deployment version associated with the version identifier and multiple microservices, and perform online code insertion and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices;
[0108] The decompression module 14 is used to decompress each of the code compression packages, obtain the class files corresponding to each of the microservices, and merge all the node coverage files to obtain a total code coverage file;
[0109] The generation module 15 is used to generate a code coverage report for the deployment version, the source code, all the class files and the total code coverage file through the jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier.
[0110] In one embodiment, if Figure 6 As shown, the packaging module 13 includes:
[0111] An acquisition unit 31 is used to generate a deployment version corresponding to the version identifier through the deployment center, and acquire the deployment version through a webhook interface;
[0112] An allocating unit 32, configured to allocate the microservice associated with the deployment version through the deployment center based on a resource optimization mechanism;
[0113] A compiling unit 33, configured to push the source code to the assigned microservices and instruct each microservice to compile according to the received source code;
[0114] The detection unit 34 is used to detect that each of the microservices returns a compiled completion instruction, and determine that the deployment of each of the microservices is complete.
[0115] For the specific limitations of the code coverage report generating device, please refer to the limitations of the code coverage report generating method above, which will not be repeated here. Each module in the above-mentioned code coverage report generating device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0116] In one embodiment, a computer device is provided. The computer device may be a client or a server. The internal structure diagram thereof may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a readable storage medium and an internal memory. The readable storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the readable storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a code coverage report generation method is implemented.
[0117] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the code coverage report generating method in the above embodiment is implemented.
[0118] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the code coverage report generation method in the above embodiment is implemented.
[0119] 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 computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0120] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0121] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for generating a code coverage report, characterized in that: include: Receive a test request, and obtain a version identifier in the test request; Obtaining a source code file corresponding to the version identifier from the code platform, and pushing the source code file to a deployment center; Deployment based on the source code file is performed through the deployment center to obtain a deployment version associated with the version identifier and a plurality of microservices, and online code insertion and code packaging operations are performed on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices; Decompress each of the code compression packages to obtain a class file corresponding to each of the microservices, and merge all of the node coverage files to obtain a total code coverage file; Generate a code coverage report for the deployment version, the source code, all the class files and the total code coverage file by using the jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier; The deploying based on the source code file through the deployment center to obtain a deployment version associated with the version identifier and a plurality of microservices includes: Generate a deployment version corresponding to the version identifier through the deployment center, and obtain the deployment version through the webhook interface; Based on a resource optimization mechanism, allocating the microservice associated with the deployment version through the deployment center; Pushing the source code to the assigned microservices, and instructing each microservice to compile according to the received source code; Detecting that each of the microservices returns a compiled completion instruction, and determining that the deployment of each of the microservices is complete; The allocating the microservice associated with the deployment version through the deployment center based on the resource optimization mechanism includes: Reading the current deployment list through the deployment center, and obtaining the historical source code corresponding to the historical deployment version in the current deployment list; The deployment center compares the source code with each of the acquired historical source codes to obtain a repetition rate corresponding to each of the historical source codes; Querying the historical microservices associated with the historical deployment version corresponding to the historical source code corresponding to the maximum repetition rate; Record the queried historical microservice as a microservice associated with the deployment version; The performing of online code plugging and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices includes: Install the jacoco plug-in tool on the deployed microservice; Perform code dump operation on each microservice by using the jacoco plug-in tool installed in each microservice to obtain a node coverage file corresponding to each microservice; Perform code packaging operations on each microservice by using the jacoco plug-in tool installed in each microservice to obtain a code compression package corresponding to each microservice; The code coverage report generation is performed on the deployment version, the source code, all the class files and the total code coverage file by the jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier, including: All the class files are merged and deduplicated to obtain a total class file; According to the total code coverage file, color-mark and count each line in the source code to obtain the marked source code and the instrumentation coverage rate; The deployment version, the total class file, the marked source code and the instrumentation coverage are associated with each other, and the code coverage report is generated.
2. The code coverage report generation method according to claim 1, characterized in that: After obtaining the code coverage report corresponding to the version identifier, the method includes: Receive an access request, and obtain a target version identifier in the access request; Querying a code coverage report corresponding to the target version identifier, and performing test uncovered extraction on the found code coverage report to obtain a plurality of untested code lines; Generate test cases based on all the untested code lines to obtain recommended test cases; The test recommendation case and the found code coverage report are returned to the terminal corresponding to the access request.
3. The code coverage report generation method according to claim 2, characterized in that: The generating of test cases according to all the untested code lines to obtain test recommended cases includes: Performing code decomposition on each of the untested codes to decompose code entities; Generating unit use cases for each of the code entities to obtain unit use cases corresponding to each of the code entities; All the unit use cases are merged to obtain the test recommended use cases.
4. A code coverage report generating device, characterized in that: include: A receiving module, used for receiving a test request and obtaining a version identifier in the test request; A push module, used to obtain a source code file corresponding to the version identifier from a code platform, and push the source code file to a deployment center; A packaging module, used to perform deployment based on the source code file through the deployment center, obtain a deployment version associated with the version identifier and multiple microservices, and perform online code insertion and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices; A decompression module is used to decompress each of the code compression packages, obtain the class files corresponding to each of the microservices, and merge all the node coverage files to obtain a total code coverage file; A generation module is used to generate a code coverage report for the deployment version, the source code, all the class files and the total code coverage file through a jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier; The packaging module includes: an acquisition unit, configured to generate a deployment version corresponding to the version identifier through the deployment center, and acquire the deployment version through a webhook interface; an allocating unit, configured to allocate the microservice associated with the deployment version through the deployment center based on a resource optimization mechanism; A compiling unit, configured to push the source code to the assigned microservices and instruct each microservice to compile according to the received source code; A detection unit, used to detect that each of the microservices returns a compiled completion instruction, and determine that the deployment of each of the microservices is complete; The allocating the microservice associated with the deployment version through the deployment center based on the resource optimization mechanism includes: Reading the current deployment list through the deployment center, and obtaining the historical source code corresponding to the historical deployment version in the current deployment list; The deployment center compares the source code with each of the acquired historical source codes to obtain a repetition rate corresponding to each of the historical source codes; Querying the historical microservices associated with the historical deployment version corresponding to the historical source code corresponding to the maximum repetition rate; Record the queried historical microservice as a microservice associated with the deployment version; The performing of online code plugging and code packaging operations on each of the microservices to obtain a node coverage file and a code compression package corresponding to each of the microservices includes: Install the jacoco plug-in tool on the deployed microservice; Perform code dump operation on each microservice by using the jacoco plug-in tool installed in each microservice to obtain a node coverage file corresponding to each microservice; Perform code packaging operations on each microservice by using the jacoco plug-in tool installed in each microservice to obtain a code compression package corresponding to each microservice; The code coverage report generation is performed on the deployment version, the source code, all the class files and the total code coverage file by the jacoco plug-in tool to obtain a code coverage report corresponding to the version identifier, including: All the class files are merged and deduplicated to obtain a total class file; According to the total code coverage file, color-mark and count each line in the source code to obtain the marked source code and the instrumentation coverage rate; The deployment version, the total class file, the marked source code and the instrumentation coverage are associated with each other, and the code coverage report is generated.
5. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the code coverage report generating method according to any one of claims 1 to 3 is implemented.
6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for generating a code coverage report according to any one of claims 1 to 3 is implemented.
