Method and device for obtaining differential coverage of application code
By using basic mirroring and version control algorithms for application deployment and differentiated code analysis in software research and development and testing, the problems of high maintenance costs and low testing efficiency of testers in the existing technology are solved, and efficient differentiated coverage calculation and report generation are achieved.
Patent Information
- Application Number
- CN202011302318.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-19
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2040-11-19
AI Technical Summary
The existing method of obtaining differentiated coverage of application code requires testers to carry out a large amount of data maintenance, resulting in high R&D and maintenance costs, high requirements for testing scenarios, which cannot meet the testing needs and low testing efficiency.
By deploying the application based on the basic image, recording the execution trajectory of the tested code, combining the version control algorithm and the structure analyzer, the differentiated code of the tested code and the baseline code is obtained, and finally mapping the differentiated code and execution trajectory into the tested code to calculate the differentiated coverage of the application code.
There is no need to add or modify the configuration of the tested code, which reduces the tester's maintenance workload for test cases and code, significantly improves the efficiency of software development and testing, and supports differentiated coverage analysis of diverse test scenarios and branch versions.
Smart Images

Figure CN113760307B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for obtaining differentiated coverage of application codes. Background Art
[0002] In the process of software application development, software testing is an important means of detecting application code. By calculating the coverage of test cases on application code, the detection of application code can be achieved. When the application function changes, the application code will also change. By calculating the differential coverage of the application code before and after the change, the application code can be evaluated more accurately.
[0003] Most of the current differentiated coverage systems associate test case modules with application code modules to be tested, and dynamically maintain the association between test case modules and application code modules to be tested. By obtaining the target test case corresponding to the application code to be tested, the target test case is executed to test the application code to obtain the differentiated coverage of the test case on the application code.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0005] The existing method of obtaining differentiated coverage of application code requires testers to perform data maintenance, has high code development and maintenance costs, and has high requirements for test scenarios. It cannot meet testing needs and has low testing efficiency. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a method and device for obtaining differentiated coverage of application code, which does not require adding or modifying the configuration of the tested code, reduces the maintenance workload of testers on test cases and codes, and improves the efficiency of software development and testing.
[0007] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for obtaining differential coverage of application codes is provided.
[0008] A method for obtaining differential coverage of application code, comprising: deploying an application according to a tested code based on a base image, testing the deployed application, recording the execution trajectory of the tested code, wherein the execution trajectory is monitored and counted by a coverage test tool agent included in the base image; compiling the tested code through a project object model based on a version control algorithm to obtain a class file; running a structure analyzer on the class file to obtain differential code between the tested code and a baseline code, wherein the baseline code is the code to be differentially compared with the tested code; mapping the differential code and the execution trajectory to the tested code to obtain differential coverage of the application code.
[0009] Optionally, based on the base image, application deployment according to the code under test includes: compiling the code under test; building a test environment for the application based on the base image; modifying the startup parameters of the test environment to deploy the application, the startup parameters including the IP address and port number of the server on which the application is deployed.
[0010] Optionally, running a structural analyzer on the class file to obtain differentiated code between the tested code and the baseline code includes: using the structural analyzer to obtain differentiated class files between the tested code and the baseline code; and performing comparative analysis on the class file and the differentiated class file to obtain differentiated code.
[0011] Optionally, based on the version control algorithm, compiling the code under test through the project object model includes: using the version control algorithm provided by JGit to copy the code under test to the differential coverage system; and compiling the code under test through the project object model included in the differential coverage system.
[0012] Optionally, after recording the execution trace of the tested code, the method further includes: storing the execution trace in a differential coverage system by remotely controlling reading and writing.
[0013] Optionally, the differential code supports differential code based on differences between different branches and differential code based on differences between different versions of the same branch.
[0014] Optionally, after obtaining the differential coverage of the application code, it also includes: generating a differential coverage report, and the label of the differential coverage report includes the branch and version number of the tested code, the branch and version number of the baseline code, and the application identifier.
[0015] According to another aspect of an embodiment of the present invention, a device for obtaining differentiated coverage of application codes is provided.
[0016] A device for obtaining differential coverage of application code, comprising: a test execution module, used to deploy applications according to a tested code based on a basic image, test the deployed application, and record the execution trajectory of the tested code, wherein the execution trajectory is monitored and counted by a coverage test tool agent included in the basic image; a code compilation module, used to compile the tested code through a project object model based on a version control algorithm to obtain a class file; a differential analysis module, used to run a structural analyzer on the class file to obtain differential code between the tested code and a baseline code, wherein the baseline code is the code to be differentially compared with the tested code; and a coverage calculation module, used to map the differentiated code and the execution trajectory to the tested code to obtain the differential coverage of the application code.
[0017] According to yet another aspect of an embodiment of the present invention, an electronic device for acquiring differentiated coverage of application codes is provided.
[0018] An electronic device for obtaining differentiated coverage of application codes, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method for obtaining differentiated coverage of application codes provided in an embodiment of the present invention.
[0019] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0020] A computer-readable medium stores a computer program, which, when executed by a processor, implements a method for obtaining differentiated coverage of application codes provided in an embodiment of the present invention.
[0021] An embodiment of the above invention has the following advantages or beneficial effects: by deploying applications according to the tested code based on the basic image, and testing the deployed applications, the execution trajectory of the tested code is recorded, and the execution trajectory is monitored and counted by the coverage test tool agent included in the basic image; based on the version control algorithm, the tested code is compiled through the project object model to obtain a class file; the structure analyzer is run on the class file to obtain the differentiated code between the tested code and the baseline code; the differentiated code and the execution trajectory are mapped to the tested code to obtain the differentiated coverage of the application code, which can realize differentiated coverage analysis for differentiated codes of different versions of source code, support parsing of differentiated codes of different branches of single source code and multiple source codes or different version numbers of the same branch and obtain corresponding differentiated coverage reports, without adding or modifying the configuration of the tested code, reducing the maintenance workload of testers on test cases and codes, and greatly improving the efficiency of software development and testing. By uploading each generated report to the unified storage platform according to the custom path rules, and viewing the report by requesting the report path of the unified storage platform, unified management of the report is achieved, which is convenient for viewing and comparison, and further improves the efficiency of software development and testing. In addition, according to the technical solution of the present invention, one-click deployment of the test environment can also be achieved, which simplifies the test operation and improves the test efficiency.
[0022] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0024] Figure 1 is a schematic diagram of main steps of a method for obtaining differential coverage of application codes according to an embodiment of the present invention;
[0025] Figure 2 is a schematic diagram of an implementation flow of a method for obtaining differentiated coverage according to an embodiment of the present invention;
[0026] Figure 3 is a schematic diagram of main modules of a device for obtaining differentiated coverage of application codes according to an embodiment of the present invention;
[0027] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0028] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0029] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0030] The current differentiated coverage systems mostly perform coverage testing based on the relationship between test cases and application codes, which not only wastes a lot of manpower and time, but also requires research on code logic and places high demands on developers. Therefore, the development and subsequent maintenance costs are very high.
[0031] When performing differentiated coverage testing, it may involve differential coverage calculations for codes in different branches of the application, or it may involve differential coverage calculations for different versions of codes in the same branch. Therefore, the test scenarios and test requirements are relatively diverse, and a differentiated coverage testing method that can adapt to diverse test scenarios is needed.
[0032] In order to solve the above technical problems, the present invention provides a method for obtaining differentiated coverage of application codes. For testers' manual testing and interface automation testing in web applications, the method supports parsing differentiated codes of different version numbers of the same branch of single source code and multi-source code and obtaining corresponding differentiated coverage reports, supports viewing historical reports, does not require adding or modifying configurations for test codes, does not increase the maintenance workload of testers on use cases and codes, combines coverage report acquisition and test environment deployment on one platform, realizes one-click deployment of test environment, and greatly improves the efficiency of software development and testing.
[0033] The technical solution of the present invention mainly consists of three parts, namely: test execution, differentiated coverage system and application deployment platform. The differentiated coverage system is mainly used to deploy the test environment with one click, perform differentiated coverage analysis, and obtain differentiated code coverage reports.
[0034] The one-click deployment test environment is to deploy the test environment of a certain branch and version of a certain application (i.e., the application's tested code) by calling the compilation, construction, and deployment APIs of the application deployment platform. The premise is to use the agent monitoring of the coverage test tool agent jacocoagent as the basic image. The coverage test tool agent monitors the execution of the tested code in real time after the application is started. When the application is deployed on the application deployment platform, the application test can be carried out, and the execution track data of the tested code can be statistically analyzed through the coverage test tool agent in the basic image.
[0035] When obtaining the differential coverage of the code, the differential coverage system uses JGit (JGit is a lightweight pure Java class library used to implement access to the Git version control system and provide a core version control algorithm) to copy the tested code of the remote code platform to the differential coverage system, and compile the tested code through the project object model maven tool of the differential coverage system itself, and then establish a connection with the application deployed on the application deployment platform through the network, remotely obtain or download the execution track data (exec format file) of the tested code to the differential coverage system, and then run the structural analyzer on the class file generated after the differential coverage system compiles the tested code, establish a coverage model, and finally generate a coverage report corresponding to the differentiated code. In particular, the differential coverage algorithm of the present invention supports differential coverage based on different branch codes and differential coverage based on different versions of the same branch. Code differentiation filters non-java files, spaces, and test files, and only recognizes the differentiation of java files.
[0036] In order to facilitate testers to view historical reports, the differentiated coverage report generated each time is uploaded to the unified data storage platform. The report tag is named "branch name + new version number + old version number + timestamp", which is helpful to compare the test coverage of different versions and help testers cover business scenarios more comprehensively. According to an embodiment of the present invention, the branch name is the branch name of the tested code, the new version number is the version number of the tested code, the old version number is the version number of the baseline code, and the timestamp is the test time.
[0037] Figure 1 FIG. 1 is a schematic diagram of the main steps of a method for obtaining differential coverage of application code according to an embodiment of the present invention. Figure 1 As shown, the method for obtaining differentiated coverage of application codes according to an embodiment of the present invention mainly includes the following steps S101 to S104.
[0038] Step S101: Based on the base image, the application is deployed according to the tested code, and the deployed application is tested, and the execution track of the tested code is recorded. The execution track is monitored and counted by the coverage test tool agent included in the base image;
[0039] Step S102: Based on the version control algorithm, compile the tested code through the project object model to obtain a class file;
[0040] Step S103: running a structure analyzer on the class file to obtain differential codes between the tested code and the baseline code, where the baseline code is the code to be differentially compared with the tested code;
[0041] Step S104: Map the differentiated code and execution trace to the code under test to obtain the differentiated coverage of the application code.
[0042] According to an embodiment of the present invention, in step S101, based on the basic image, when the application is deployed according to the tested code, the following steps may be specifically performed:
[0043] Compile the code under test;
[0044] Build an application test environment based on the basic image;
[0045] Modify the startup parameters of the test environment to deploy the application. The startup parameters include the IP address and port number of the server where the application is deployed.
[0046] The premise of differential coverage system to obtain analysis coverage is to first create a basic image with coverage test tool agent jacocoagent; then compile the tested code of the application and build the test environment, where the test environment needs to be built in combination with the previously made basic image. The basic image is the environment required to start an application, including the server operating system and version, tomcat (Web application server) and version, java and version, Nginx (HTTP and reverse proxy web server) and version, etc. In the embodiment of the present invention, in order to monitor the execution process of the tested code of the application, it is necessary to add the coverage test tool agent jacocoagent.
[0047] After that, the application deployment is completed by modifying the startup parameters of the tomcat JVM (Java virtual machine) of the application test environment. Specifically, the settings of each parameter are as follows:
[0048] set JAVA_OPTS="-javaagent:your localPath\jacocoagent.jar,includes=*,output=tcpserver,port=8080,address=IP";
[0049] Where your localPath is the address where jacocoagent.jar is stored on the application, includes=* means collecting all classes, output=tcpserver means obtaining the execution trace exec file of the tested code without stopping the application service, and address and port are the IP address and port number of the server where the application is deployed.
[0050] Use the one-click execution function of the differential coverage system to deploy the application to the application deployment platform, and copy and compile the code under test on the differential coverage system server. The baseline code and the code under test may be based on different branches or different versions of the same branch. The baseline code is the code to be differentially compared with the code under test. After the application is started, use the terminal command to check whether jacocoagen.jar exists on the server to confirm whether the coverage test tool agent jacocoagent is included in the base image. At the same time, the differential coverage system can also obtain the class files (class files) generated after the code under test is compiled.
[0051] After the application is deployed, the code test can be performed on the application connection deployed on the application deployment platform to record the code execution track of the tested application. The code execution track is monitored and counted by the coverage test tool agent.
[0052] In the embodiment of the present invention, the differentiated coverage system supports two test execution modes, one is manual execution (in the application test environment, functional testing is performed according to pre-designed test cases), and the other is interface automated execution.
[0053] Among them, the execution of interface automation is to connect the differentiated coverage system and the test interface automation management platform. By calling the existing interface use cases maintained by the user in the intest interface automation management platform, the interface automation test is performed on the test environment. During the test execution process, jacocoagent will monitor which background codes the foreground test behavior has "walked" through, and record them into an exec format type file, that is, the code execution trajectory. After recording the code execution trajectory of the application under test, the code execution trajectory can also be stored in the differentiated coverage system through remote control reading and writing (RemoteControlReader).
[0054] According to an embodiment of the present invention, based on the version control algorithm, when the tested code is compiled through the project object model, the tested code is copied to the differential coverage system using the version control algorithm provided by JGit; then, the tested code is compiled through the project object model included in the differential coverage system. Specifically, the differential coverage system uses JGit to copy the tested code deployed remotely or the tested code in the distributed version control system Git to the coverage test system, and the tested code is compiled through the Maven tool of the coverage test system itself to obtain the class file of the tested code.
[0055] According to the technical solution of the present invention, there is no strict execution order for the steps of applying deployment and testing to obtain the execution trajectory of the code under test, and the step of compiling the code under test to obtain the class file. They can be executed simultaneously or one after another, as long as the execution trajectory and class file of the code under test can be obtained.
[0056] Then, the differential coverage system will perform differential coverage calculation, which specifically includes step S103 of running a structural analyzer on the class file of the tested code to analyze the tested code and the baseline code to obtain differentiated code, and step S104 of mapping the differentiated code and the execution trace to the tested code to obtain the differentiated coverage of the application code.
[0057] In one embodiment of the present invention, when using a structural analyzer to analyze the tested code and the baseline code to obtain differentiated code, it can specifically include: using the structural analyzer to obtain differentiated class files of the tested code and the baseline code; comparing and analyzing the class files of the tested code and the differentiated class files to obtain differentiated code.
[0058] Structural analysis can make developers understand the overall implementation framework of the software system and reduce panic and confusion during development. The code structure analyzer is used to perform structural analysis on the code. Specifically, it performs differential analysis on the tested code and the baseline code based on the branch name and / or version number to obtain differential class information in the tested code and the baseline code, such as: java class file name, class in the class file, method information in the class (method md5 value, method name, method input parameter, etc.), compare the number of lines added and deleted in the code with different version numbers, etc. The class file generated when the code is compiled records the classes included in the code and the methods included in each class, as well as the calling relationship between classes, such as: java class file name, class in the class file, method information in the class (method md5 value, method name, method input parameter, etc.). By comparing and analyzing the class file of the tested code and the differentiated class file, the differentiated code can be obtained. Specifically, after obtaining the differentiated class information, the differentiated class information is compared with the class information of the tested code to map the added, deleted or modified class information in the class information of the tested code, thereby obtaining the differentiated code.
[0059] Then, the execution trace of the tested code generated during the test execution and the differentiated code can be mapped to the tested code to visualize the granularity of each line of code, and then calculate the differentiated coverage. When calculating the differentiated coverage, it is calculated through a code coverage analysis tool, where the code coverage analysis tool is, for example, the analysis function of the jacoco open source code.
[0060] After obtaining the differential coverage of the application code, a differential coverage report can also be generated, and the labels of the differential coverage report include the branch name and version number of the tested code, the branch name and version number of the baseline code, and the application identifier (such as the application name) and timestamp. In addition, since the memory of the differential coverage system is limited, each generated report can be uploaded to a unified storage platform according to certain path rules. To view the report at the front desk, you only need to request the report path to view the report.
[0061] Among them, the coverage report can include line coverage, class coverage, method coverage, branch coverage, instruction coverage, cyclomatic complexity and other related coverage. You can get coverage layer by layer according to the class name and method name, and finally reach the code layer. At the code layer, the code added to the tested code compared to the baseline code will be marked with a "+" on the left, and the code deleted from the tested code compared to the baseline code will be marked with a "-" on the left. And add different color backgrounds to the code lines to more clearly show whether the code is executed. For example: the red background means that no instructions in this line are executed during the test execution, that is, there is no coverage; the yellow background means that only part of the instructions in this line are executed, that is, partial execution; the green background means that all instructions in this line are covered, that is, full coverage. The meanings of these coverage rates will be introduced one by one below.
[0062] 1. Row coverage:
[0063] If all class files are compiled with debug information, the coverage of each line can be calculated. When at least one instruction is assigned to a source line and executed, the source line is considered to have been executed;
[0064] 2. Class coverage:
[0065] When at least one method in a class has been executed, the class is considered to have been executed. Jacoco considers constructors and static initialization methods to be executed methods. If a Java interface type contains a static initialization method, the interface is also considered an executable class;
[0066] 3. Method coverage:
[0067] Each non-abstract method contains at least one instruction. When at least one instruction is executed, the method is considered to have been executed. Since Jacoco is based on the bytecode level, constructors and static initialization methods are also calculated as methods. Some of these methods may not be directly mapped to the source code, such as the default constructor or the initialization command of the constant;
[0068] 4. Branch coverage:
[0069] Includes all if and switch statements. This metric counts the total number of branches in a method, determining the number of branches that are executed and not executed;
[0070] 5. Instruction coverage:
[0071] The smallest counting unit of Jacoco is a single Java binary code instruction. Instruction coverage provides information on whether the code is executed;
[0072] 6. Cyclomatic complexity:
[0073] Jacoco can also calculate the complexity for each non-abstract method, and finally calculate the complexity of the class, package and group. According to the definition of cyclomatic complexity by McCabe1996, it is the minimum number of all possible paths in a method in (linear) combination. Therefore, complexity can be used as a basis for measuring whether the unit test fully covers all scenarios.
[0074] Figure 2 FIG. 1 is a schematic diagram of the implementation flow of the method for obtaining differentiated coverage according to an embodiment of the present invention. Figure 2 As shown, according to an embodiment of the present invention, the method for obtaining differentiated coverage mainly includes the following steps:
[0075] 1. Receive the information of the tested code and the baseline code input by the user. Specifically, the information of the tested code includes, for example, the code path, project name, branch number, and version number of the tested code; the information of the baseline code includes the code path, project name, branch number, and version number of the baseline code;
[0076] 2. Deploy the application to the application deployment platform according to the tested code. The specific deployment process is to perform the following steps in sequence: code compilation, application test environment construction, and modification of JVM startup parameters to deploy the application. Each step can only be executed if the previous step is executed successfully. In addition, the execution log is saved during the execution of each step. If the execution fails, the specific operation status can be viewed by querying the execution log;
[0077] 3. Based on the version control algorithm, copy the tested code to the differential coverage platform;
[0078] 4. Compile the code under test to obtain the class file of the code under test;
[0079] 5. Test the deployed applications on the application deployment platform, and monitor and record the execution track of the tested code through the coverage test tool agent jacocoagent;
[0080] 6. Run the structural analyzer on the class files of the tested code to obtain the difference between the tested code and the baseline code;
[0081] 7. Calculate the differential coverage based on the execution trace of the tested code and the differentiated code;
[0082] 8. Generate differentiated coverage reports;
[0083] 9. Save the report to the unified storage platform and view the report through the report path.
[0084] According to the technical solution of the present invention, step 5 may also be performed after step 2 and before step 3 and step 4.
[0085] Figure 3 FIG. 1 is a schematic diagram of the main modules of the apparatus for obtaining the differential coverage of application codes according to an embodiment of the present invention. Figure 3 As shown, the apparatus 300 for obtaining differential coverage of application codes according to an embodiment of the present invention mainly includes a test execution module 301 , a code compilation module 302 , a differential analysis module 303 and a coverage calculation module 304 .
[0086] The test execution module 301 is used to deploy applications according to the tested code based on the basic image, test the deployed applications, and record the execution track of the tested code, which is monitored and counted by the coverage test tool agent included in the basic image;
[0087] A code compiling module 302 is used to compile the tested code through a project object model based on a version control algorithm to obtain a class file;
[0088] A differential analysis module 303 is used for running a structural analyzer on the class file to obtain differential codes of the tested code and a baseline code, wherein the baseline code is the code to be differentially compared with the tested code;
[0089] The coverage calculation module 304 is used to map the differentiated code and the execution trace to the tested code to obtain the differentiated coverage of the application code.
[0090] According to one embodiment of the present invention, the test execution module 301 may also be used to:
[0091] Compile the code under test;
[0092] Build an application test environment based on the basic image;
[0093] The startup parameters of the test environment are modified to deploy the application, wherein the startup parameters include an IP address and a port number of a server on which the application is deployed.
[0094] According to another embodiment of the present invention, the differential analysis module 303 may also be used to:
[0095] Using the structure analyzer to obtain the differential class files of the tested code and the baseline code;
[0096] The class file and the differentiated class file are compared and analyzed to obtain differentiated codes.
[0097] According to another embodiment of the present invention, the code compiling module 302 may also be used for:
[0098] Using the version control algorithm provided by JGit, copy the tested code to the differential coverage system;
[0099] The code under test is compiled through a project object model included in the differential coverage system.
[0100] According to another embodiment of the present invention, the apparatus 300 for obtaining differential coverage of application codes may further include a trace storage module (not shown in the figure) for:
[0101] After recording the execution trace of the tested code, the execution trace is stored in the differential coverage system through remote control reading and writing.
[0102] According to yet another embodiment of the present invention, the differential code supports differential code based on differences between different branches and differential code based on differences between different versions of the same branch.
[0103] According to another embodiment of the present invention, the apparatus 300 for obtaining differential coverage of application codes may further include a report generating module (not shown in the figure) for:
[0104] After obtaining the differential coverage of the application code, a differential coverage report is generated, and a label of the differential coverage report includes the branch and version number of the tested code, the branch and version number of the baseline code, and the application identifier.
[0105] According to the technical solution of the embodiment of the present invention, by deploying the application according to the tested code based on the basic image, and testing the deployed application, recording the execution track of the tested code, the execution track is monitored and counted by the coverage test tool agent included in the basic image; based on the version control algorithm, the tested code is compiled through the project object model to obtain the class file; the structure analyzer is run on the class file to obtain the differential code of the tested code and the baseline code; the differential code and the execution track are mapped to the tested code to obtain the differential coverage of the application code, which can realize the differential coverage analysis of the differential code of different versions of source code, support the analysis of the differential code of different branches of single source code and multiple source code or the same branch with different version numbers and obtain the corresponding differential coverage report, without adding or modifying the configuration of the tested code, reducing the maintenance workload of the test personnel on the test cases and codes, and greatly improving the efficiency of software development and testing. By uploading the generated report to the unified storage platform according to the custom path rules, and viewing the report by requesting the report path of the unified storage platform, the unified management of the report is realized, which is convenient for viewing and comparison, and further improves the efficiency of software development and testing. In addition, according to the technical solution of the present invention, it is also possible to deploy the test environment with one click, which simplifies the test operation and improves the test efficiency.
[0106] Figure 4 An exemplary system architecture 400 is shown to which the method for obtaining differential coverage of application codes or the apparatus for obtaining differential coverage of application codes according to an embodiment of the present invention can be applied.
[0107] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0108] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Terminal devices 401, 402, 403 can be installed with various client applications, such as web browser applications, tested applications, interactive applications, etc. (only examples).
[0109] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0110] Server 405 may be a server that provides various services, such as a background management server (only an example) that provides support for responding to requests sent by users using terminal devices 401, 402, and 403. The background management server may analyze and process the received application test request and other data, and feed back the processing results to the terminal device.
[0111] It should be noted that the method for obtaining the differentiated coverage of application codes provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the device for obtaining the differentiated coverage of application codes is generally set in the server 405 .
[0112] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0113] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device or a server suitable for implementing an embodiment of the present invention. Figure 5 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0114] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0115] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0116] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0117] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0118] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0119] The units or modules involved in the embodiments of the present invention may be implemented in software or hardware. The units or modules described may also be provided in a processor. For example, they may be described as: a processor including a test execution module, a code compilation module, a differential analysis module, and a coverage calculation module. The names of these units or modules do not, in some cases, constitute limitations on the units or modules themselves. For example, the test execution module may also be described as "a module for deploying applications based on the base image and the code under test, and testing the deployed applications, and recording the execution trajectory of the code under test, wherein the execution trajectory is monitored and counted by the coverage test tool agent included in the base image".
[0120] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by a device, the device includes: based on the base image, deploying the application according to the tested code, testing the deployed application, recording the execution track of the tested code, and the execution track is monitored and counted by the coverage test tool agent included in the base image; based on the version control algorithm, compiling the tested code through the project object model to obtain a class file; running a structural analyzer on the class file to obtain the differential code of the tested code and the baseline code, and the baseline code is the code to be differentially compared with the tested code; mapping the differential code and the execution track to the tested code to obtain the differential coverage of the application code.
[0121] According to the technical solution of the embodiment of the present invention, by deploying the application according to the tested code based on the basic image, and testing the deployed application, recording the execution track of the tested code, the execution track is monitored and counted by the coverage test tool agent included in the basic image; based on the version control algorithm, the tested code is compiled through the project object model to obtain the class file; the structure analyzer is run on the class file to obtain the differential code of the tested code and the baseline code; the differential code and the execution track are mapped to the tested code to obtain the differential coverage of the application code, which can realize the differential coverage analysis of the differential code of different versions of source code, support the analysis of the differential code of different branches of single source code and multiple source code or the same branch with different version numbers and obtain the corresponding differential coverage report, without adding or modifying the configuration of the tested code, reducing the maintenance workload of the test personnel on the test cases and codes, and greatly improving the efficiency of software development and testing. By uploading the generated report to the unified storage platform according to the custom path rules, and viewing the report by requesting the report path of the unified storage platform, the unified management of the report is realized, which is convenient for viewing and comparison, and further improves the efficiency of software development and testing. In addition, according to the technical solution of the present invention, it is also possible to deploy the test environment with one click, which simplifies the test operation and improves the test efficiency.
[0122] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for obtaining differential coverage of application code, characterized in that: include: Based on the base image, the application is deployed according to the tested code, and the deployed application is tested, and the execution track of the tested code is recorded. The execution track is monitored and counted by the coverage test tool agent included in the base image; Based on the version control algorithm, the tested code deployed remotely or the tested code in the distributed version control system is copied to the coverage test system, and the tested code is compiled through the project object model included in the coverage test system to obtain a class file; Running a structural analyzer on the class file to obtain differential code between the code under test and a baseline code, wherein the baseline code is code to be differentially compared with the code under test; Mapping the differentiated code and the execution trace to the tested code to obtain differentiated coverage of the application code; Wherein, based on the basic image, deploying the application according to the tested code includes: compiling the tested code; building a test environment for the application based on the basic image; modifying the startup parameters of the test environment to deploy the application, wherein the startup parameters include the IP address and port number of the server on which the application is deployed; Compiling the code under test through the project object model based on the version control algorithm includes: using the version control algorithm provided by JGit to copy the code under test to the differential coverage system; compiling the code under test through the project object model included in the differential coverage system; After recording the execution trace of the tested code, the method further includes: storing the execution trace in a differential coverage system by remotely controlling reading and writing.
2. The method according to claim 1, characterized in that Running a structural analyzer on the class file to obtain differential code between the tested code and the baseline code includes: The tested code baseline code uses the structure analyzer to obtain the differential class files of the tested code and the baseline code; The class file and the differentiated class file are compared and analyzed to obtain differentiated codes.
3. The method according to claim 1, characterized in that The differential code supports differential code based on differences between different branches and differential code based on differences between different versions of the same branch.
4. The method according to claim 3, characterized in that: After obtaining the differential coverage of the application code, it also includes: A differential coverage report is generated, and a label of the differential coverage report includes the branch and version number of the tested code, the branch and version number of the baseline code, and an application identifier.
5. A device for obtaining differentiated coverage of application code, characterized in that: include: A test execution module is used to deploy applications based on the base image and the tested code, test the deployed applications, and record the execution track of the tested code, which is monitored and counted by the coverage test tool agent included in the base image; A code compilation module is used to copy the tested code deployed remotely or the tested code in the distributed version control system to the coverage test system based on the version control algorithm, and compile the tested code through the project object model included in the coverage test system to obtain a class file; A differential analysis module, used for running a structural analyzer on the class file to obtain differential codes of the tested code and a baseline code, wherein the baseline code is the code to be differentially compared with the tested code; A coverage calculation module, used for mapping the differentiated code and the execution trace into the tested code to obtain the differentiated coverage of the application code; The test execution module is also used to: compile the code under test; Building a test environment for the application based on the base image; modifying startup parameters of the test environment to deploy the application, the startup parameters including the IP address and port number of the server on which the application is deployed; The code compilation module is further used to: copy the tested code into the differential coverage system by using the version control algorithm provided by JGit; compile the tested code by using the project object model included in the differential coverage system; The trace storage module is used to: after recording the execution trace of the tested code, store the execution trace in the differential coverage system by remote control reading and writing.
6. An electronic device for obtaining differentiated coverage of application codes, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.
7. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Code coverage rate analysis method and device and electronic equipment thereof
CN111831321A