Method and device for determining incremental code test coverage rate, electronic equipment and storage medium

By obtaining and analyzing the test results of incremental code in web front-end projects and calculating the test coverage of incremental code, the problem that the existing technology cannot be applied to web front-end projects and is inaccurate and efficient, achieving more efficient code test coverage.

CN119025427APending Publication Date: 2024-11-26CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411169032.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-23
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

The existing methods of determining incremental code test coverage cannot be applied to web front-end projects, and there are insufficient accuracy and efficiency.

Method used

By obtaining the test files of the web front-end project of the web page, determining the incremental code from the global code, executing the test command, using the test statistics plug-in to analyze the test result file, extracting the first line number and the second line number set, and calculating the incremental code Test coverage.

Benefits of technology

It improves the accuracy and efficiency of incremental code test coverage, shortens the development cycle of front-end projects, and improves development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025427A_ABST
    Figure CN119025427A_ABST
Patent Text Reader

Abstract

The invention relates to a method and device for determining an incremental code test coverage rate, electronic equipment and a storage medium, and belongs to the technical field of software testing. The method comprises the following steps: acquiring a to-be-tested file of a web front-end item of a webpage, and determining an incremental code of the to-be-tested file from a global code of the to-be-tested file; executing a test command on the to-be-tested file to obtain a test result file of the to-be-tested file, running a plug-in execution command, and positioning a test statistics plug-in from a web front-end item of a webpage; analyzing the test result file based on the test statistics plug-in to extract a first line number from the incremental code to obtain a first line number set, and determining a second line number of the incremental code which is not covered by the test to obtain a second line number set; according to the first line number set and the second line number set, the first test coverage rate of the incremental code of the to-be-tested file is obtained, and therefore the test coverage rate of the incremental code of the to-be-tested file of the web front-end project of the webpage can be accurately and efficiently obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of software testing, and in particular to a method, device, electronic device and storage medium for determining incremental code test coverage. Background Art

[0002] In the related art, the method for determining the incremental code test coverage is often applicable to programs developed in the Java language, but cannot be used in web front-end projects. In addition, there are problems of low accuracy and low efficiency in determining the incremental code test coverage. Summary of the invention

[0003] The present disclosure provides a method, device, electronic device, computer-readable storage medium and computer program product for determining incremental code test coverage, so as to at least solve the problem that the related technology cannot be applied in web front-end projects and the accuracy and efficiency of determining incremental code test coverage are low.

[0004] The technical solution of the present disclosure is as follows:

[0005] According to a first aspect of an embodiment of the present disclosure, a method for determining incremental code test coverage is provided, the method comprising: obtaining a file to be tested of a web front-end project, and determining the incremental code of the file to be tested from the global code of the file to be tested; executing a test command on the file to be tested, obtaining a test result file of the file to be tested, running a plug-in execution command, and locating a test statistics plug-in from the web front-end project of the web page; analyzing the test result file based on the test statistics plug-in to extract a first line number from the incremental code to obtain a first line number set, and determining a second line number of the incremental code not covered by the test to obtain a second line number set; obtaining a first test coverage of the incremental code of the file to be tested based on the first line number set and the second line number set.

[0006] According to a second aspect of an embodiment of the present disclosure, a device for determining incremental code test coverage is provided, the device comprising: a first determination module, configured to obtain a file to be tested of a web front-end project, and determine the incremental code of the file to be tested from the global code of the file to be tested; an execution module, configured to execute a test command on the file to be tested, obtain a test result file of the file to be tested, run a plug-in execution command, and locate a test statistics plug-in from the web front-end project of the web page; a second determination module, configured to analyze the test result file based on the test statistics plug-in to extract a first line number from the incremental code to obtain a first line number set, and determine a second line number of the incremental code not covered by the test to obtain a second line number set; an acquisition module, configured to obtain a first test coverage of the incremental code of the file to be tested according to the first line number set and the second line number set.

[0007] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the method for determining incremental code test coverage as described in the first aspect.

[0008] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method for determining incremental code test coverage as described in the first aspect.

[0009] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the method for determining incremental code test coverage as described in the first aspect is implemented.

[0010] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: through the file to be tested of the web front-end project, the incremental code of the file to be tested is determined from the global code of the file to be tested; the test command is executed on the file to be tested to obtain the test result file of the file to be tested, the plug-in execution command is run, the test statistics plug-in is located from the web front-end project of the web page, and the test result file is analyzed based on the test statistics plug-in to extract the first line number from the incremental code to obtain a first line number set, and determine the second line number of the incremental code not covered by the test to obtain a second line number set, and obtain the first test coverage of the incremental code of the file to be tested based on the first line number set and the second line number set. Therefore, the present disclosure can obtain the test coverage of the incremental code of the file to be tested of the web front-end project, improve the accuracy and efficiency of the test coverage of the incremental code, and by obtaining the test coverage of the incremental code, the development cycle of the front-end project can be shortened and the development efficiency of the front-end project can be improved.

[0011] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.

[0013] Figure 1 It is a flowchart of a method for determining incremental code test coverage according to the first embodiment of the present disclosure.

[0014] Figure 2 It is a flowchart of a method for determining incremental code test coverage according to the second embodiment of the present disclosure.

[0015] Figure 3 It is a flowchart of a method for determining incremental code test coverage according to the third embodiment of the present disclosure.

[0016] Figure 4 It is a block diagram of an apparatus for determining incremental code test coverage according to a first embodiment of the present disclosure.

[0017] Figure 5 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0018] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0019] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0020] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this disclosure are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards.

[0021] It should be noted that the acquisition, transmission, storage, use, and processing of data in the technical solution of the present disclosure are in compliance with the relevant provisions of relevant laws and regulations. In the embodiments of the present disclosure, certain software, components, models, and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present disclosure, but it does not mean that the applicant has or will necessarily use the solution.

[0022] Figure 1 It is a flowchart of a method for determining incremental code test coverage according to the first embodiment of the present disclosure.

[0023] like Figure 1 As shown, the method for determining incremental code test coverage in the first embodiment of the present disclosure includes the following steps:

[0024] S101, obtaining a file to be tested of a web front-end project, and determining an incremental code of the file to be tested from the global code of the file to be tested.

[0025] It should be noted that the present disclosure does not limit the specific method for obtaining the file to be tested of the web front-end project, which can be selected according to actual conditions.

[0026] Optionally, the root directory of the web front-end project may be determined, and a folder location instruction may be executed to locate a target folder in the root directory. In response to the target folder being non-empty, a file to be tested may be determined from the target folder.

[0027] It should be noted that the target folder can be set according to the actual situation of the web front-end project.

[0028] Among them, incremental code refers to the code that changes (new additions and modifications) during the software development process.

[0029] In the embodiment of the present disclosure, after the file to be tested is acquired, the incremental code of the file to be tested may be determined from the global code of the file to be tested.

[0030] Optionally, a Git diff command can be executed on the file to be tested based on the built-in module of nodejs to obtain a string, the obtained string can be split into an array, and the changed code can be determined from the global code of the file to be tested through a regular expression, that is, the incremental code of the file to be tested can be obtained.

[0031] S102, executing a test command on the file to be tested, obtaining a test result file of the file to be tested, running a plug-in execution command, and locating a test statistics plug-in from a web front-end project.

[0032] It should be noted that you can obtain the test script corresponding to the file to be tested, and configure the test parameters required to execute the test command. In the test environment, execute the test command on the file to be tested. The test command will trigger the execution of the test script, thereby realizing the test of the file to be tested and obtaining the test result file of the file to be tested.

[0033] In the disclosed embodiment, the test statistics plug-in is written in a script program based on the JavaScript language and is integrated into the web front-end project based on dependencies.

[0034] Optionally, the root directory of the web front-end project can be determined, and the metadata file of the web front-end project can be obtained from the root directory, the dependency information can be obtained from the metadata file, and the plug-in in the web front-end project of the web page can be located based on the dependency information.

[0035] It should be noted that the test statistics plug-in is integrated into the web front-end project in the form of a node package manager (npm) dependency, that is, the test statistics plug-in is integrated and used in the web front-end project code in the form of an npm dependency package.

[0036] Among them, npm is the default package management tool for the node.js platform, which can install, share, distribute code, and manage project dependencies.

[0037] S103, analyzing the test result file based on the test statistics plug-in to extract the first line number from the incremental code to obtain a first line number set, and determining the second line number of the incremental code not covered by the test to obtain a second line number set.

[0038] It should be noted that, since the test statistics plug-in needs to analyze the test result file, a target command for executing the test statistics plug-in can be configured after the test command.

[0039] In an embodiment of the present disclosure, a target command can be sent to a test statistics plug-in. After the test statistics plug-in receives the target command, the test statistics plug-in analyzes the test result file to extract the first line number from the incremental code to obtain a first line number set, and determines the second line number of the incremental code not covered by the test to obtain a second line number set.

[0040] S104: Obtain a first test coverage of the incremental code of the file to be tested according to the first line number set and the second line number set.

[0041] It should be noted that in order to ensure code quality, the source code needs to be covered by test cases and have certain requirements for test coverage. The test coverage of incremental code is often more practical. Incremental unit testing breaks down test tasks into smaller units. Only the latest changes need to be tested each time, which allows for quick testing and easier location and debugging of problems. It can also reduce the overall testing cycle and improve development efficiency.

[0042] In an embodiment of the present disclosure, after obtaining the first line number set and the second line number set, a first test coverage of the incremental code of the file to be tested can be obtained according to the first line number set and the second line number set.

[0043] For example, if there are N lines of incremental code in the first line number set and M lines of incremental code not covered by the test in the second line number set, then the first test coverage of the incremental code of the file to be tested is

[0044] In summary, according to the method for determining the test coverage of incremental code provided by the embodiment of the present invention, the incremental code of the file to be tested is determined from the global code of the file to be tested through the file to be tested of the web front-end project of the web page, the test command is executed on the file to be tested, and the test result file of the file to be tested is obtained, the plug-in execution command is run, and the test statistics plug-in is located from the web front-end project of the web page, and the test result file is analyzed based on the test statistics plug-in to extract the first line number from the incremental code to obtain a first line number set, and determine the second line number of the incremental code not covered by the test to obtain a second line number set, and obtain the first test coverage of the incremental code of the file to be tested based on the first line number set and the second line number set. Therefore, the present invention can obtain the test coverage of the incremental code of the file to be tested of the web front-end project of the web page, improve the accuracy and efficiency of the test coverage of the incremental code, and by obtaining the test coverage of the incremental code, the development cycle of the front-end project can be shortened and the development efficiency of the front-end project can be improved.

[0045] Figure 2 It is a flowchart of a method for determining incremental code test coverage according to the second embodiment of the present disclosure.

[0046] like Figure 2 As shown, the method for determining incremental code test coverage in the second embodiment of the present disclosure includes the following steps:

[0047] As a possible implementation method, based on the above implementation, the specific process of obtaining the file to be tested of the web front-end project in step S101 includes steps S201 to S202:

[0048] S201, determine the root directory of the web front-end project, and run a folder location instruction to locate a target folder in the root directory.

[0049] It should be noted that the root directory of the web front-end project can be pre-configured based on the user's operation instructions. The root directory of the web front-end project includes the top-level folders of all sub-files and sub-directories of the web front-end project.

[0050] For example, the root directory of a web front-end project includes, but is not limited to, the project's configuration files, source code, resource files, configuration files of the project dependency management tool, etc.

[0051] It should be noted that after determining the root directory of the web front-end project, if the current directory is inconsistent with the root directory of the web front-end project, the current directory can be switched to the root directory of the web front-end project by running the switch directory command.

[0052] In the embodiment of the present disclosure, the folder locating instruction includes target path information of the target folder. By executing the folder locating instruction, the target path information is read to locate the target folder in the root directory.

[0053] S202: In response to the target folder being not empty, determine a file to be tested from the target folder.

[0054] Optionally, whether the target folder is non-empty is determined by judging whether there is an lcov.info file in the target folder, wherein the lcov.info file is a coverage information file (text file) generated by the lcov tool, and the lcov.info file includes source files and coverage information of each source file.

[0055] For example, in response to the existence of the lcov.info file in the target folder, it is determined that the target folder is not empty; in response to the absence of the lcov.info file in the target folder, it is determined that the target folder is empty.

[0056] S203: Determine the incremental code of the file to be tested from the global code of the file to be tested.

[0057] S204, executing a test command on the file to be tested to obtain a test result file of the file to be tested.

[0058] For the relevant contents of step S203 to step S204, please refer to the above embodiment and will not be repeated here.

[0059] As a possible implementation method, based on the above implementation, the specific process of running the plug-in execution command in step S102 to locate the test statistics plug-in from the web front-end project includes steps S205 to S206:

[0060] S205, obtaining the metadata file of the web front-end project from the root directory.

[0061] It should be noted that for web front-end projects, the metadata file usually refers to the package.json file. The metadata file includes the configuration information of the web front-end project, such as the project name, version, dependency list and other configuration information of the web front-end project.

[0062] S206, obtaining dependency information from the metadata file, and locating the plug-in in the web front-end project based on the dependency information.

[0063] In the disclosed embodiment, by reading and parsing the metadata file, dependency information can be obtained from the metadata file, and the test statistics plug-in in the web front-end project of the web page can be located based on the dependency information.

[0064] It should be noted that the dependency information includes but is not limited to the name information and version number of the dependency.

[0065] In the disclosed embodiment, the test statistics plug-in is written in a script program based on the JavaScript language and is integrated into the web front-end project based on dependencies.

[0066] Optionally, the test statistics plugin also supports integration into the pipeline.

[0067] S207, analyzing the test result file based on the test statistics plug-in to extract the first line number from the incremental code to obtain a first line number set.

[0068] As a possible implementation method, based on the above implementation, the specific process of determining the second line number of the incremental code not covered by the test in step S103 and obtaining the second line number set includes steps S208 to S2010:

[0069] S208, determining a third set of line numbers not covered by the test.

[0070] In an embodiment of the present application, a third line number set not covered by the test can be determined from the test result file, where the third line number set includes the third line number not covered by the original code test in the global code, that is, all uncovered line numbers.

[0071] S209: Determine the line numbers belonging to the incremental code from the third line number set according to the first line number set.

[0072] It should be noted that after obtaining the third line number set, the intersection of the first line number set and the third line number set can be obtained. The intersection of the first line number set and the third line number set is the line number belonging to the incremental code.

[0073] S2010, obtaining a second line number set based on the line numbers belonging to the incremental code determined in the third line number set.

[0074] In the embodiment of the present disclosure, after determining the line numbers belonging to the incremental code from the third line number set, the second line numbers of the incremental code not covered by the test can be determined, that is, the second line number set is obtained.

[0075] S2011, obtaining a first test coverage rate of the incremental code of the file to be tested according to the first line number set and the second line number set.

[0076] In summary, according to the method for determining incremental code test coverage provided by the embodiment of the present disclosure, the root directory of the web front-end project is determined, and the folder positioning instruction is run to locate the target folder in the root directory. In response to the target folder being non-empty, the file to be tested is determined from the target folder, the incremental code of the file to be tested is determined from the global code of the file to be tested, the test command is executed on the file to be tested, and the test result file of the file to be tested is obtained. The metadata file of the web front-end project is obtained from the root directory, the dependency information is obtained from the metadata file, and the plug-in in the web front-end project of the web page is located based on the dependency information. The test result file is analyzed based on the test statistics plug-in to extract the first line number from the incremental code, obtain the first line number set, and determine the first line number not covered by the test. Three line number sets, according to the first line number set, determine the line numbers belonging to the incremental code from the third line number set, according to the third line number set, determine the line numbers belonging to the incremental code to obtain the second line number set, according to the first line number set and the second line number set, obtain the first test coverage of the incremental code of the file to be tested. Therefore, the present invention analyzes the test result file based on the test statistics plug-in to obtain the first line number set and the second line number set, and obtains the first test coverage of the incremental code of the file to be tested according to the first line number set and the second line number set, which improves the accuracy and efficiency of obtaining the test coverage of the incremental code. By obtaining the test coverage of the incremental code, the quality of the code is guaranteed, the development and testing cycle of the front-end project is shortened, and the development efficiency of the front-end project is improved.

[0077] Figure 3 It is a flowchart of a method for determining incremental code test coverage according to the third embodiment of the present disclosure.

[0078] like Figure 3 As shown, the method for determining incremental code test coverage in the third embodiment of the present disclosure includes the following steps:

[0079] S301, obtaining a file to be tested of a web front-end project, and determining an incremental code of the file to be tested from the global code of the file to be tested.

[0080] S302, executing a test command on the file to be tested, obtaining a test result file of the file to be tested, running a plug-in execution command, and locating a test statistics plug-in from a web front-end project.

[0081] S303, analyzing the test result file based on the test statistics plug-in to extract the first line number from the incremental code to obtain a first line number set, and determining the second line number of the incremental code not covered by the test to obtain a second line number set.

[0082] S304: Obtain a first test coverage rate of the incremental code of the file to be tested according to the first line number set and the second line number set.

[0083] For the relevant contents of step S301 to step S304, please refer to the above embodiment and will not be repeated here.

[0084] S305: Generate first table filling information of the file to be tested according to the second line number set and the first test coverage.

[0085] The first table filling information includes the second line number of the incremental code not covered by the test and the first test coverage value.

[0086] S306, filling in the statistical table of the test results based on the first table filling information of the file to be tested, to generate a target statistical table.

[0087] In an embodiment of the present disclosure, the third line number not covered by the original code test in the global code and the second test coverage rate not covered by the test globally can be obtained, and based on the third line number and the second test coverage rate not covered by the test globally, the second table filling information of the file to be tested is generated, the filling formats of the first table filling information and the second table filling information are differentially configured, and the statistical table of the test results is filled to generate a target statistical table.

[0088] It should be noted that the identification information of the fill content of different areas in the statistical table can be obtained, and based on the identification information, the fill content required for each fill area can be determined from the first table fill information and the second table fill information, and the fill format of the first table fill information and the second table fill information after differentiated configuration is obtained, and the fill content is filled into the statistical table according to the fill area and the fill format to generate the target statistical table.

[0089] It should be noted that the present disclosure does not limit the setting of the filling formats of the first form filling information and the second form filling information.

[0090] Optionally, the filling format includes but is not limited to font type, font color, background color, etc.

[0091] For example, in order to more intuitively display the second line number of the incremental code not covered by the test, the background color of the second line number of the incremental code not covered by the test can be set to red, and the background color of the third line number of the original code not covered by the test in the global code can be set to light red.

[0092] S307, sending the target statistical table to the display device for display.

[0093] In the embodiment of the present disclosure, after the target statistical table is acquired, the target statistical table may be sent to a display device. Accordingly, after receiving the target statistical table, the display device may visually display it on a display interface of the display device.

[0094] In an embodiment of the present disclosure, a Hypertext Markup Language (HTML) generated by a parsing tool on the server side can be obtained, and the second line number and the third line number of the file to be tested can be added to the target class corresponding to the HTML; and / or, the display format of the second line number and the third line number can be differentially configured to generate a target HTML and send it to the server side for web page rendering.

[0095] Optionally, the test result file can be parsed by cheerio, a parsing tool on the server side, to generate HTML.

[0096] Among them, cheerio is a fast, flexible and powerful library in the Node.js environment, which is used to parse, manipulate, and render HTML, XML, and similarly structured documents.

[0097] For example, with respect to the display format, the background color of the second row of numbers may be set to yellow, and the background color of the third row of numbers may be set to light red.

[0098] In summary, according to the method for determining the test coverage of incremental code provided by the embodiment of the present disclosure, by obtaining the file to be tested of the web front-end project of the web page, determining the incremental code of the file to be tested from the global code of the file to be tested, executing the test command on the file to be tested, obtaining the test result file of the file to be tested, running the plug-in execution command, locating the test statistics plug-in from the web front-end project of the web page, analyzing the test result file based on the test statistics plug-in to extract the first line number from the incremental code to obtain the first line number set, and determining the second line number of the incremental code not covered by the test to obtain the second line number set, obtaining the first test coverage of the incremental code of the file to be tested according to the first line number set and the second line number set, generating the first table filling information of the file to be tested according to the second line number set and the first test coverage, filling the statistical table of the test results based on the first table filling information of the file to be tested, generating the target statistical table, and sending the target statistical table to the display device for display, thereby, the present disclosure can not only accurately and efficiently obtain the test coverage of the incremental code, but also can visually display the test coverage of the incremental code in the terminal and the server, and at the same time, can directly locate the line number of the incremental code not covered by the test.

[0099] Figure 4 The block diagram of the device for determining the incremental code test coverage according to the first embodiment of the present disclosure is applicable to a server.

[0100] like Figure 4 As shown, the device 400 for determining incremental code test coverage according to an embodiment of the present disclosure includes: a first determination module 401 , an execution module 402 , a second determination module 403 and an acquisition module 404 .

[0101] The first determination module 401 is configured to obtain a file to be tested of a web front-end project, and determine an incremental code of the file to be tested from a global code of the file to be tested;

[0102] The execution module 402 is configured to execute a test command on the file to be tested, obtain a test result file of the file to be tested, run a plug-in execution command, and locate a test statistics plug-in from the web front-end project;

[0103] The second determination module 403 is configured to analyze the test result file based on the test statistics plug-in to extract the first line number from the incremental code to obtain a first line number set, and determine the second line number of the incremental code not covered by the test to obtain a second line number set;

[0104] The acquisition module 404 is configured to use the first line number set and the second line number set to obtain a first test coverage of the incremental code of the file to be tested.

[0105] In one embodiment of the present disclosure, after obtaining the first test coverage of the incremental code of the file to be tested, the device 400 is also configured to: generate first table filling information of the file to be tested by using the second line number set and the first test coverage; fill in the statistical table of the test results based on the first table filling information of the file to be tested to generate a target statistical table; and send the target statistical table to a display device for display.

[0106] In one embodiment of the present disclosure, the device 400 is also configured to: obtain the third line number not covered by the original code test in the global code and the second test coverage rate not covered by the test globally; based on the third line number and the second test coverage rate not covered by the test globally, generate the second table filling information of the file to be tested; differentially configure the filling formats of the first table filling information and the second table filling information, and fill the statistical table of the test results to generate the target statistical table.

[0107] In one embodiment of the present disclosure, after obtaining the first test coverage of the incremental code of the file to be tested, the device 400 is further configured to: obtain the hypertext markup language HTML generated by the parsing tool of the server; add the second line number and the third line number of the file to be tested to the target class corresponding to the HTML; and / or, differentially configure the display format of the second line number and the third line number to generate a target HTML and send it to the server for web page rendering.

[0108] In one embodiment of the present disclosure, the second determination module 403 is further configured to: determine a third line number set not covered by the test; determine the line numbers belonging to the incremental code from the third line number set based on the first line number set; determine the line numbers belonging to the incremental code from the third line number set to obtain the second line number set.

[0109] In one embodiment of the present disclosure, the acquisition module 401 is further configured to: determine the root directory of the web front-end project, and execute a folder location instruction to locate a target folder in the root directory; in response to the target folder being non-empty, determine the file to be tested from the target folder.

[0110] In one embodiment of the present disclosure, the execution module 500 is also configured to: determine the root directory of the web front-end project, and obtain the metadata file of the web front-end project from the root directory; obtain dependency information from the metadata file, and locate the plug-in in the web front-end project of the web page based on the dependency information.

[0111] In one embodiment of the present disclosure, the test statistics plug-in is written in a script program based on the JavaScript language and is integrated into the web front-end project based on dependencies.

[0112] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0113] In summary, the device for determining the test coverage of incremental code provided by the embodiment of the present disclosure determines the incremental code of the file to be tested from the global code of the file to be tested through the file to be tested of the web front-end project of the web page, executes the test command on the file to be tested, obtains the test result file of the file to be tested, runs the plug-in execution command, locates the test statistics plug-in from the web front-end project of the web page, analyzes the test result file based on the test statistics plug-in to extract the first line number from the incremental code to obtain the first line number set, and determines the second line number of the incremental code not covered by the test to obtain the second line number set, and obtains the first test coverage of the incremental code of the file to be tested based on the first line number set and the second line number set. Therefore, the present disclosure can obtain the test coverage of the incremental code of the file to be tested of the web front-end project of the web page, improves the accuracy and efficiency of the test coverage of the incremental code, and by obtaining the test coverage of the incremental code, the development cycle of the front-end project can be shortened and the development efficiency of the front-end project can be improved.

[0114] Figure 5 It is a block diagram of an electronic device according to an exemplary embodiment.

[0115] like Figure 5 As shown, the electronic device 500 includes:

[0116] The memory 510 and the processor 520, a bus 530 connecting different components (including the memory 510 and the processor 520), the memory 510 stores a computer program, and when the processor 520 executes the program, the method for determining the incremental code test coverage described in the embodiment of the present disclosure is implemented.

[0117] Bus 530 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.

[0118] The electronic device 500 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 500, including volatile and non-volatile media, removable and non-removable media.

[0119] The memory 510 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 540 and / or cache memory 550. The electronic device 500 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 560 may be used to read and write non-removable, non-volatile magnetic media ( Figure 5 not shown, usually called a "hard drive"). Although Figure 5 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 530 via one or more data medium interfaces. The memory 510 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.

[0120] A program / utility 580 having a set (at least one) of program modules 570 may be stored, for example, in the memory 510, such program modules 570 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 570 generally perform the functions and / or methods of the embodiments described in the present disclosure.

[0121] The electronic device 500 may also communicate with one or more external devices 590 (e.g., keyboard, pointing device, display 591, etc.), one or more devices that enable a user to interact with the electronic device 500, and / or any device that enables the electronic device 500 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 592. Furthermore, the electronic device 500 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) through a network adapter 593. Figure 5As shown, the network adapter 593 communicates with other modules of the electronic device 500 via the bus 530. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device 500, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0122] The processor 520 executes various functional applications and data processing by running the programs stored in the memory 510 .

[0123] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the method for determining incremental code test coverage in the embodiment of the present disclosure, and will not be repeated here.

[0124] In summary, the electronic device provided by the embodiment of the present disclosure can execute the method for determining the test coverage of incremental code as described above, determine the incremental code of the file to be tested from the global code of the file to be tested through the file to be tested of the web front-end project of the web page, execute the test command on the file to be tested, obtain the test result file of the file to be tested, run the plug-in execution command, locate the test statistics plug-in from the web front-end project of the web page, analyze the test result file based on the test statistics plug-in to extract the first line number from the incremental code to obtain the first line number set, and determine the second line number of the incremental code not covered by the test to obtain the second line number set, and obtain the first test coverage of the incremental code of the file to be tested based on the first line number set and the second line number set. Therefore, the present disclosure can obtain the test coverage of the incremental code of the file to be tested of the web front-end project of the web page, improve the accuracy and efficiency of the test coverage of the incremental code, and by obtaining the test coverage of the incremental code, the development cycle of the front-end project can be shortened and the development efficiency of the front-end project can be improved.

[0125] In order to implement the above embodiments, the present disclosure also proposes a computer-readable storage medium.

[0126] Wherein, when the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device can implement the method for determining the incremental code test coverage as described above. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0127] In order to implement the above embodiments, the present disclosure also provides a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, the method for determining incremental code test coverage as described above is implemented.

[0128] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0129] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A method for determining incremental code test coverage, characterized in that: The method comprises: Obtain a file to be tested of a web front-end project, and determine an incremental code of the file to be tested from the global code of the file to be tested; Execute a test command on the file to be tested, obtain a test result file of the file to be tested, run a plug-in execution command, and locate a test statistics plug-in from the web front-end project of the web page; Analyzing the test result file based on the test statistics plug-in to extract a first line number from the incremental code to obtain a first line number set, and determining a second line number of the incremental code not covered by the test to obtain a second line number set; A first test coverage of the incremental code of the file to be tested is obtained according to the first line number set and the second line number set.

2. The method according to claim 1, characterized in that After obtaining the first test coverage of the incremental code of the file to be tested, the method further includes: The second line number set and the first test coverage rate are used to generate first table filling information of the file to be tested; Filling the statistical table of the test results based on the first table filling information of the file to be tested to generate a target statistical table; The target statistical table is sent to a display device for display.

3. The method according to claim 2, characterized in that The filling of the statistical table of the test results based on the first table filling information of the file to be tested to generate a target statistical table includes: Obtaining the third line number not covered by the original code test in the global code and the second test coverage rate not covered by the global test; Generate second table filling information of the file to be tested based on the third line number and the second test coverage rate not covered by the test globally; The filling formats of the first table filling information and the second table filling information are configured differently, and the statistical table of the test results is filled to generate the target statistical table.

4. The method according to any one of claims 1 to 3, characterized in that After obtaining the first test coverage of the incremental code of the file to be tested, the method further includes: Get the hypertext markup language HTML generated by the server-side parsing tool; Add the second line number and the third line number of the file to be tested to the target class corresponding to the HTML; and / or, The display formats of the second line number and the third line number are configured differently to generate target HTML and send it to the server for web page rendering.

5. The method according to claim 1, characterized in that The determining the second line number of the incremental code not covered by the test to obtain a second line number set includes: Determining a third set of line numbers not covered by the test; According to the first line number set, determining the line number belonging to the incremental code from the third line number set; The second line number set is obtained by determining the line numbers belonging to the incremental code in the third line number set.

6. The method according to any one of claims 1 to 3 or 5, characterized in that: The step of obtaining the file to be tested of the web front-end project includes: Determine the root directory of the web front-end project, and run a folder location instruction to locate a target folder in the root directory; In response to the target folder being not empty, determining the file to be tested from the target folder.

7. The method according to any one of claims 1 to 3 or 5, characterized in that: The running of the plug-in execution command to locate the plug-in from the web front-end project of the web page includes: Determine the root directory of the web front-end project, and obtain the metadata file of the web front-end project from the root directory; Dependency information is obtained from the metadata file, and the plug-in in the web front-end project of the web page is located based on the dependency information.

8. The method according to any one of claims 1 to 3 or 5, characterized in that: The test statistics plug-in is written in a script program based on the JavaScript language and is integrated into the web front-end project based on dependencies.

9. A device for determining incremental code test coverage, characterized in that: The device comprises: A first determination module is configured to obtain a file to be tested of a web front-end project, and determine an incremental code of the file to be tested from a global code of the file to be tested; An execution module is configured to execute a test command on the file to be tested, obtain a test result file of the file to be tested, run a plug-in execution command, and locate a test statistics plug-in from the web front-end project; A second determination module is configured to analyze the test result file based on the test statistics plug-in to extract a first line number from the incremental code to obtain a first line number set, and determine a second line number of the incremental code not covered by the test to obtain a second line number set; The acquisition module is configured to obtain a first test coverage of the incremental code of the file to be tested according to the first line number set and the second line number set.

10. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method for determining incremental code test coverage as described in any one of claims 1-8.

11. A computer-readable storage medium, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to execute the method for determining incremental code test coverage as described in any one of claims 1 to 8.

12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for determining incremental code test coverage according to any one of claims 1 to 8 is implemented.