Code coverage statistical method, device, electronic device and storage medium

By obtaining the number of nested if statements and the number of scenarios in the test file, the code coverage of different computer languages ​​is automatically calculated, which solves the problem of low efficiency in existing technologies and achieves efficient and accurate code coverage statistics.

CN114518998BActive Publication Date: 2025-10-28ZHEJIANG DASOUCHE SOFTWARE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011305690.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-20
Publication Date
2025-10-28
Estimated Expiration
2040-11-20

AI Technical Summary

Technical Problem

Existing code coverage statistics methods are inefficient and cannot effectively count the mutual code test coverage between different computer languages.

Method used

By acquiring test files and utilizing the nested if statements in test scripts and development code developed in different computer languages, code coverage is automatically calculated. This includes acquiring the number of first scenarios in the test scripts and the number of second scenarios in the development code, and then calculating the code coverage.

Benefits of technology

It enables automatic code test coverage statistics across different computer languages, reducing redundant testing and improving the efficiency and accuracy of code coverage statistics.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114518998B_ABST
    Figure CN114518998B_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, electronic device, and storage medium for calculating code coverage. The method includes: acquiring a test file; acquiring a first number of test script scenarios based on the test file; wherein the test script is developed using a first computer language; acquiring a second number of development code scenarios based on the number of nested if statements in the test file; wherein the development code is developed using a second computer language, and the second computer language is different from the first computer language; and acquiring a statistical result of the code coverage based on the first and second number of scenarios. This application solves the problem of low efficiency in code coverage calculation methods and enables the statistical calculation of code test coverage between different computer languages.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to statistical methods, apparatus, electronic devices, and storage media for code coverage. Background Technology

[0002] Code coverage refers to the ratio of executed code to the total code in a piece of software during its runtime; it is a crucial metric for measuring test quality. After performing unit testing, assembly testing, integration testing, and interface testing on a software product, it's necessary to assess the test quality. If the testing process only covers a small portion of the software product's code, then no matter how many test cases are written, it's difficult to ensure test quality. Conversely, if the testing process covers the vast majority of the software product's code, then the quality of the software product can be measured based on the test results. In related technologies, code coverage statistics are generally based on manual analysis of dynamic script code coverage, and currently, it's impossible to use computer tools to statistically analyze the cross-code test coverage between different computer languages, resulting in low efficiency in code coverage statistics methods.

[0003] Currently, no effective solution has been proposed to address the issue of low efficiency in statistical methods for code coverage in related technologies. Summary of the Invention

[0004] This application provides a method, apparatus, electronic device, and storage medium for calculating code coverage, to at least address the problem of low efficiency in related art methods for calculating code coverage.

[0005] In a first aspect, embodiments of this application provide a method for statistical analysis of code coverage, the method comprising:

[0006] Obtain the test file;

[0007] The first scenario number of the test script is obtained according to the test file; wherein, the test script is developed in a first computer language;

[0008] The number of second scenarios in the development code is obtained based on the number of nested if statements in the test file; wherein the development code is developed in a second computer language, and the second computer language is different from the first computer language.

[0009] Based on the first number of scenarios and the second number of scenarios, obtain the statistical results of the code coverage.

[0010] In some embodiments, obtaining the first number of scenarios for the test script based on the test file includes:

[0011] Obtain the scene name of the test file;

[0012] If a new script scene is detected based on the scene name and the scene database, the new script scene will be included in the first preset set.

[0013] The first number of scenarios is obtained based on the first preset set.

[0014] In some embodiments, obtaining the first number of scenes based on the scene name and the first preset set includes:

[0015] The test interface is filled in according to the first preset set; wherein, the first preset set stores key-value pair data consisting of the scene name and the test interface;

[0016] If the filling result is negative, return the reminder information corresponding to the filling result, and store the first preset set in the scene database;

[0017] If the filling result is yes, supplement the interface information of the test interface and store the first preset set in the scenario database;

[0018] The first number of scenarios is obtained based on the scenario database and the first preset set.

[0019] In some embodiments, the scene names for obtaining the scene database include:

[0020] Using a preset query model, a query operation is performed on the scenario database, and the scenario name is obtained based on the result of the query operation.

[0021] In some embodiments, obtaining the second scenario number of the development code based on the calculated number of nested if statements in the test file includes:

[0022] If an if statement is detected, the number of if statements at the current nesting level is stored in the second preset set;

[0023] The number of if nesting levels is calculated based on the result of the if nesting level determination.

[0024] The number of the second scene in the second preset set is calculated based on the number of if statements in the current layer and the number of if layers.

[0025] In some embodiments, obtaining the test file includes:

[0026] The test file generated during the test is read using the inputStream.

[0027] Secondly, embodiments of this application provide a code coverage statistics device, the device comprising: an acquisition module, a first scene count module, a second scene count module, and a statistics module;

[0028] The acquisition module is used to acquire test files;

[0029] The first scenario number module is used to obtain the first scenario number of the test script based on the test file; wherein the test script is developed using a first computer language;

[0030] The second scenario number module is used to obtain the second scenario number of the development code based on the nesting level of if statements in the test file; wherein the development code is developed in a second computer language, and the second computer language is different from the first computer language.

[0031] The statistics module is used to obtain the statistical results of the code coverage based on the first number of scenarios and the second number of scenarios.

[0032] In some embodiments, the first scene counting module is further configured to obtain the scene name of the test file;

[0033] When the first scene counting module detects a new script scene based on the scene name and the scene database, it counts the new script scene into a first preset set;

[0034] The first scene count module obtains the first scene count based on the first preset set.

[0035] Thirdly, embodiments of this application provide an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the statistical method for code coverage as described in the first aspect above.

[0036] Fourthly, embodiments of this application provide a storage medium storing a computer program that, when executed by a processor, implements the code coverage statistical method described in the first aspect above.

[0037] Compared to related technologies, the code coverage statistics method, apparatus, electronic device, and storage medium provided in this application embodiment, by acquiring a test file; acquiring a first number of test script scenarios based on the test file; wherein the test script is developed in a first computer language; acquiring a second number of development code scenarios based on the number of nested if statements in the test file; wherein the development code is developed in a second computer language, and the second computer language is different from the first computer language; and acquiring the statistical result of code coverage based on the first number of scenarios and the second number of scenarios, solves the problem of low efficiency in code coverage statistics methods and realizes the statistics of code test coverage between different computer languages. Attached Figure Description

[0038] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0039] Figure 1 This is a schematic diagram of an application scenario according to an embodiment of this application;

[0040] Figure 2 This is a flowchart of a code coverage statistical method according to an embodiment of this application;

[0041] Figure 3 This is a flowchart of another method for statistically analyzing code coverage according to an embodiment of this application;

[0042] Figure 4 This is a flowchart of an execution test script according to an embodiment of this application;

[0043] Figure 5 This is a flowchart of another method for statistically analyzing code coverage according to an embodiment of this application;

[0044] Figure 6 This is a flowchart illustrating the execution of development code according to an embodiment of this application;

[0045] Figure 7 This is a structural block diagram of a code coverage statistics device according to an embodiment of this application;

[0046] Figure 8 This is a structural diagram of the internal structure of a computer device according to an embodiment of this application. Detailed Implementation

[0047] To make the objectives, technical solutions, and advantages of this application clearer, the application is described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the application. All other embodiments obtained by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application. Furthermore, it is understood that although the efforts made in such a development process may be complex and lengthy, for those skilled in the art related to the content disclosed in this application, modifications to design, manufacturing, or production based on the technical content disclosed in this application are merely conventional technical means and should not be construed as insufficient disclosure of the content of this application.

[0048] In this application, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment that is mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0049] Unless otherwise defined, the technical or scientific terms used in this application shall have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms “a,” “an,” “an,” “the,” and similar words used in this application do not indicate quantity limitation and may indicate singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units not listed, or may include other steps or units inherent to these processes, methods, products, or devices. The terms “connected,” “linked,” “coupled,” and similar words used in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. “Multiple” used in this application means two or more. “And / or” describes the relationship between related objects, indicating that three relationships may exist; for example, “A and / or B” can represent: A alone, A and B simultaneously, and B alone. The terms “first,” “second,” “third,” etc., used in this application are merely to distinguish similar objects and do not represent a specific ordering of the objects.

[0050] The statistical method for code coverage provided in this application can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with server 14 via a network. Terminal 102 obtains SQL statements; server 104 uses a test file to obtain the first scenario count of the test script, and based on the nesting level of if statements in the test file, obtains the second scenario count of the development code, and then obtains the statistical result of the code coverage based on the first and second scenario counts. Server 104 sends the statistical result to terminal 102. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices, and server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.

[0051] This embodiment provides a method for calculating code coverage. Figure 2 This is a flowchart of a code coverage statistical method according to an embodiment of this application, such as... Figure 2 As shown, the process includes the following steps:

[0052] Step S202: Obtain the test file. This test file, generated during the testing process, can be read using Java's byte input stream, `inputStream`.

[0053] Step S204: Obtain the first scenario number of the test script based on the test file; wherein, the test script is developed using a first computer language. Specifically, the first computer language can be Python; the test script can be written and built based on the Robot Framework. It should be noted that the Robot Framework is a Python-based, extensible, keyword-driven automated testing framework used for acceptance-driven testing.

[0054] Step S206: Obtain the second scenario number of the development code based on the nested if statements in the test file; wherein, the development code is developed using a second computer language, and the second computer language is different from the first computer language. Specifically, the second computer language can be Java; the development code can be written based on Java. It is understood that both the first computer language and the second computer language can be any computer programming language.

[0055] Step S208: Obtain the statistical result of the code coverage based on the number of first scenarios and the number of second scenarios. Specifically, the statistical result of code coverage is obtained by comparing the number of first scenarios in the test scripts with the number of second scenarios in the development code; for example, if the number of second scenarios is 10 and the number of first scenarios is 5, then the code coverage is considered to be 50%.

[0056] Through steps S202 to S208, the first scenario count of the test script is obtained from the test file, and the second scenario count of the development code is obtained from the nested if statements in the test file. Then, the statistical results of code coverage are adaptively obtained based on the first and second scenario counts. Furthermore, the development languages ​​of the test scripts and the development languages ​​of the development code are different from each other. This allows the software tool to automatically calculate the mutual code test coverage between different computer languages ​​during the code coverage statistics process. As a result, it is possible to know how many lines of code the test scripts of the testers have covered, reducing duplicate testing and solving the problem of low efficiency in code coverage statistics methods.

[0057] In some embodiments, a method for calculating code coverage is provided. Figure 3 This is a flowchart of another code coverage statistical method according to an embodiment of this application, such as... Figure 3 As shown, the process includes the following steps:

[0058] Step S302: Obtain the scene name of the test file. This can be done by reading each line of the test file to obtain the scene name. An example of such a test file is shown below:

[0059] ***Test Case***

[0060] Test01. Used cars sorted by lowest monthly rent.

[0061] Used cars sorted by lowest monthly rent - Pass

[0062] Test02. Used cars sorted by lowest down payment.

[0063] Used cars sorted by lowest down payment - Pass

[0064] Test03. Used cars sorted by lowest price.

[0065] Used cars sorted by lowest price - Pass

[0066] Test04. Used cars sorted by highest price.

[0067] Used cars sorted by highest price - Pass

[0068] Test05. Sort used cars by shortest mileage.

[0069] Used cars sorted by shortest mileage - Pass

[0070] Test06. Used cars sorted by lowest monthly rent.

[0071] Used cars sorted by lowest monthly rent - Pass checks B-end listings based on carId or vinNumber - ApiTest07. Used cars sorted by lowest down payment.

[0072] Used cars sorted by lowest down payment - Pass checks carId or vinNumber to find the car on the platform and then displays the car - ApiTest08. Used cars sorted by lowest price

[0073] Used cars sorted by lowest price - Pass: Search by carId or vinNumber and then the car will pop up - ApiTest09. Used cars sorted by highest price

[0074] Used cars sorted by highest price - Pass checks carId or vinNumber to find cars on the platform and then displays them - ApiTest10. Used cars sorted by shortest mileage.

[0075] Used cars sorted by shortest mileage - Pass: Check B-end listings and then select a car based on carId or vinNumber - API

[0076] Taking the above test file as an example, the scene name can be obtained from each line of the file string read, such as "Test01. Used cars sorted by the lowest monthly rent".

[0077] Step S304: If a new script scene is detected based on the scene name and the scene database, the new script scene is added to the first preset set.

[0078] Specifically, stored scene names can be retrieved from the scene database. A preset query model is used to perform a query operation on the scene database, and the scene name is obtained based on the result of the query operation. This preset query module can be selected as the TestsuitRobotExample class.

[0079] The scene names read from the test file are compared with the scene names queried from the scene database. If no matching scene name is found, it is considered that a new script scene has been added. The scene name and interface information of the new script scene are stored as key-value pairs in the first preset collection. It should be noted that the first preset collection is a pre-created key-value pair collection, such as a hashmap or hashtable.

[0080] Step S306: Obtain the first scene count based on the first preset set. The first scene count can be calculated from multiple script scenes in the first preset set and their corresponding scene names.

[0081] Through steps S302 to S306 above, new script scenarios are detected based on the read test files, and the new script scenarios are stored in the first preset set so as to count the number of first scenarios of the test scripts, thereby improving the accuracy of code coverage statistics while ensuring the efficiency of code coverage statistics.

[0082] In some embodiments, the process of obtaining the first number of scenes based on the scene name and the first preset set further includes the following steps: detecting the filling result of the test interface based on the first preset set; wherein, the first preset set stores key-value pair data consisting of the scene name and the test interface; if the filling result is negative, returning a reminder message corresponding to the filling result, and storing the first preset set in the scene database; if the filling result is positive, supplementing the interface information of the test interface, and storing the first preset set in the scene database; obtaining the first number of scenes based on the scene database. It should be noted that the scene name and test interface in the first preset set are parsed using the `git push` operation, and the parsed first preset set is stored in the scene database.

[0083] The embodiments of the present application are described and illustrated below through preferred embodiments. Figure 4 This is a flowchart of an execution test script according to an embodiment of this application, such as... Figure 4 As shown, the process includes the following steps:

[0084] Step S402: Start running the test script; obtain the script scenario name.

[0085] Step S404: Determine if it is a newly added script scenario; if so, add the newly added script scenario to the first preset set. The first preset set stores key-value pairs consisting of the scenario name and test interface of the script scenario.

[0086] Step S406: Determine whether the test interface has been filled in the script scenario; if yes, add the interface information to the first preset set; if no, send a reminder message to remind that the test interface has not been filled in.

[0087] Step S408: Store the first preset set in the scene database, and obtain the first scene number based on the scene database.

[0088] Based on the test file example above, the code example for this test script is shown below:

[0089]

[0090]

[0091]

[0092] Through the above embodiments, the system determines whether the test interface information has been filled in, and prompts the user to supplement the test interface if the interface information is not filled in, thus avoiding errors in the number of covered scenarios. At the same time, the interface information and scenario names are stored in the scenario database, so that statistics can be performed in the form of a time period in the future, thereby further improving the accuracy of code coverage statistics.

[0093] In some embodiments, a method for calculating code coverage is provided. Figure 5 This is a flowchart of another code coverage statistical method according to an embodiment of this application, such as... Figure 5 As shown, the process includes the following steps:

[0094] Step S502: When an if statement is detected, the number of if statements in the current nesting level is stored in the second preset set; the number of if levels is calculated based on the judgment result of the number of if nesting levels; and the number of second scenarios in the second preset set is calculated based on the number of if statements in the current nesting level and the number of if levels.

[0095] The embodiments of the present application are described and illustrated below through preferred embodiments. Figure 6 This is a flowchart of executing development code according to an embodiment of this application, such as... Figure 6 As shown, the process includes the following steps:

[0096] Step S602: Start running the development code; read each line of the file sequentially and determine whether the line is an if statement.

[0097] Step S604: If the judgment result of step S602 is yes, record the nesting level of if, add{ to the stack, and record the number of ifs at the current level in the second preset set map.

[0098] Step S606: Determine if the line is}; if so, determine the nesting level, remove { from the stack, and decrement the current level by one.

[0099] Step S608: Calculate the total number of scenes in each map. This total is the number of the second scene. Specifically, for if statements at the same level, the number of scenes is calculated as the number of if statements + 1. For example, if there are 2 if statements at the same level, the number of the second scene is 3. For nested if statements, the number of scenes is calculated as follows: For example, if there are 3 nested if statements, with 2 if statements in the first level, 2 in the second level, and 1 in the third level, the number of the second scene is calculated as (2+1)+(2+1)+(1+1).

[0100] The code example for this development is shown below:

[0101]

[0102]

[0103] Through the above step S502, by reading each line of file content in a loop, the number of if statements in the current nested if layer is stored, and the if layer number is calculated, the second scenario number is calculated based on the current if statement number and the if layer number. This makes the statistical method for the second scenario number simple and effective, thereby further improving the efficiency of code coverage statistics.

[0104] It should be understood that, although Figures 2 to 6 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figures 2 to 6 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0105] This embodiment also provides a code coverage statistics device for implementing the above embodiments and preferred embodiments, which will not be repeated hereafter. As used below, the terms "module," "unit," "subunit," etc., can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0106] Figure 7 This is a structural block diagram of a code coverage statistics device according to an embodiment of this application, such as... Figure 7 As shown, the device includes: an acquisition module 72, a first scene count module 74, a second scene count module 76, and a statistics module 78; the acquisition module 72 is used to acquire a test file; the first scene count module 74 is used to acquire a first scene count of the test script based on the test file; wherein the test script is developed using a first computer language; the second scene count module 76 is used to acquire a second scene count of the development code based on the number of nested if statements in the test file; wherein the development code is developed using a second computer language, and the second computer language is different from the first computer language; the statistics module 78 is used to acquire a statistical result of the code coverage based on the first scene count and the second scene count.

[0107] Through the above embodiments, the first scenario counting module 74 obtains the first scenario count of the test script through the test file, the second scenario counting module 76 obtains the second scenario count of the development code through the nested if statements of the test file, and the statistics module 78 adaptively obtains the statistical results of code coverage based on the first scenario count and the second scenario count. Moreover, the development language of the test script and the development language of the development code are different from each other, so that during the code coverage statistics process, the software tool can automatically count the mutual code test coverage between different computer languages, thereby knowing how many lines of code the test scripts of the testers have covered, reducing duplicate testing, and solving the problem of low efficiency in code coverage statistics methods.

[0108] In some embodiments, the first scene counting module 74 is further used to obtain the scene name of the test file; when the first scene counting module 74 detects a new script scene based on the scene name and the scene database, the new script scene is counted into a first preset set; the first scene counting module 74 obtains the first scene count based on the first preset set.

[0109] In some embodiments, the first scene count module 74 is further configured to detect the filling result of the test interface according to the first preset set; wherein, the first preset set stores key-value pair data consisting of the scene name and the test interface; if the filling result is negative, the first scene count module 74 returns a reminder message corresponding to the filling result and stores the first preset set in the scene database; if the filling result is positive, the first scene count module 74 supplements the interface information of the test interface and stores the first preset set in the scene database; the first scene count is obtained according to the scene database.

[0110] In some embodiments, the first scene number module 74 is further configured to perform a query operation on the scene database using a preset query model, and obtain the scene name based on the result of the query operation.

[0111] In some embodiments, the second scene counting module 76 is further configured to store the number of current if statements in the nested if statement is detected into a second preset set; the second scene counting module 76 calculates the if level number based on the judgment result of the nested if statement; the second scene counting module 76 calculates the second scene count in the second preset set based on the current if statement number and the if level number.

[0112] In some embodiments, the acquisition module 72 is also used to read the test file generated during the test via an inputStream.

[0113] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0114] In this embodiment, a computer device is provided, which may be a server. Figure 8 This is a structural diagram of the internal structure of a computer device according to an embodiment of this application, such as... Figure 8 As shown. The computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database stores test files. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements the aforementioned statistical method for code coverage.

[0115] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0116] This embodiment also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.

[0117] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0118] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:

[0119] S1, obtain the test file.

[0120] S2, obtain the first scenario number of the test script based on the test file; wherein, the test script is developed in a first computer language.

[0121] S3, based on the nested if statements in the test file, obtain the second scenario number of the development code; wherein the development code is developed in a second computer language, and the second computer language is different from the first computer language.

[0122] S4. Based on the number of the first scenario and the number of the second scenario, obtain the statistical results of the code coverage.

[0123] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated here.

[0124] Furthermore, in conjunction with the code coverage statistics methods in the above embodiments, this application embodiment can provide a storage medium for implementation. This storage medium stores a computer program; when executed by a processor, the computer program implements any of the code coverage statistics methods in the above embodiments.

[0125] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0126] Those skilled in the art should understand that the technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments have been described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0127] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present patent application shall be determined by the appended claims.

Claims

1. A statistical method for code coverage, characterized in that, The method includes: Obtain the test file; the test file is a file generated during the test. The first scenario number of the test script is obtained according to the test file; wherein, the test script is developed in a first computer language; The second scenario number of the development code is obtained based on the nesting level of if statements in the development code; wherein the development code is developed in a second computer language, and the second computer language is different from the first computer language. Based on the first number of scenarios and the second number of scenarios, obtain the statistical results of the code coverage.

2. The statistical method according to claim 1, characterized in that, The step of obtaining the first scenario number of the test script based on the test file includes: Obtain the scene name of the test file; If a new script scene is detected based on the scene name and the scene database, the new script scene will be included in the first preset set. The first number of scenarios is obtained based on the first preset set.

3. The statistical method according to claim 2, characterized in that, The step of obtaining the first number of scenes based on the first preset set includes: The test interface is filled in according to the first preset set; wherein, the first preset set stores key-value pair data consisting of the scene name and the test interface; If the filling result is negative, return the reminder information corresponding to the filling result, and store the first preset set in the scene database; If the filling result is yes, supplement the interface information of the test interface and add the first preset set to the scenario database; The first number of scenarios is obtained from the scenario database.

4. The statistical method according to claim 2, characterized in that, The scene names for obtaining the scene database include: Using a preset query model, a query operation is performed on the scenario database, and the scenario name is obtained based on the result of the query operation.

5. The statistical method according to claim 1, characterized in that, The step of obtaining the second scenario number of the development code based on the nesting level of if statements in the development code includes: If an if statement is detected, the number of if statements at the current nesting level is stored in the second preset set; The number of if nesting levels is calculated based on the result of the if nesting level determination. The number of the second scene in the second preset set is calculated based on the number of if statements in the current layer and the number of if layers.

6. The statistical method according to any one of claims 1 to 5, characterized in that, The acquisition of the test file includes: The test file generated during the test is read using the inputStream.

7. A statistical device for code coverage, characterized in that, The device includes: an acquisition module, a first scene count module, a second scene count module, and a statistics module; The acquisition module is used to acquire test files; the test files are files generated during the testing process. The first scenario number module is used to obtain the first scenario number of the test script based on the test file; wherein the test script is developed using a first computer language; The second scenario number module is used to obtain the second scenario number of the development code based on the number of nested if statements in the development code; wherein the development code is developed in a second computer language, and the second computer language is different from the first computer language; The statistics module is used to obtain the statistical results of the code coverage based on the first number of scenarios and the second number of scenarios.

8. The statistical device according to claim 7, characterized in that, The first scene counting module is also used to obtain the scene name of the test file; When the first scene counting module detects a new script scene based on the scene name and the scene database, it counts the new script scene into a first preset set; The first scene count module obtains the first scene count based on the first preset set.

9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the statistical method for code coverage as described in any one of claims 1 to 6.

10. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the statistical method for code coverage as described in any one of claims 1 to 6 at runtime.

Citation Information

Patent Citations

  • Test method and device, electronic equipment and storage medium

    CN110825631A

  • Non-invasive MC / DC coverage rate statistical analysis method

    CN111813670A