CN115129575A - Code coverage result generation method and device - Google Patents

Code coverage result generation method and device Download PDF

Info

Publication number
CN115129575A
CN115129575A CN202110314432.XA CN202110314432A CN115129575A CN 115129575 A CN115129575 A CN 115129575A CN 202110314432 A CN202110314432 A CN 202110314432A CN 115129575 A CN115129575 A CN 115129575A
Authority
CN
China
Prior art keywords
code
code coverage
coverage result
incremental
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110314432.XA
Other languages
Chinese (zh)
Inventor
孙文东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Kingsoft Cloud Network Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN202110314432.XA priority Critical patent/CN115129575A/en
Publication of CN115129575A publication Critical patent/CN115129575A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a method and a device for generating a code coverage result, which relate to the technical field of software testing, and the method comprises the following steps: in the process of testing software to be tested based on a preset test case, when the condition that the preset condition is met is detected, acquiring a full code coverage result corresponding to a currently executed test case; acquiring an incremental code corresponding to a currently executed test case; and obtaining a current incremental code coverage result based on the full-amount code coverage result and the incremental code. Based on the processing, the incremental code coverage result can be obtained, and the acquisition cost of the incremental code coverage result is reduced.

Description

Code coverage result generation method and device
Technical Field
The invention relates to the technical field of software testing, in particular to a code coverage result generation method and device.
Background
With the rapid development of network technology, more and more software is applied to various aspects of life, work, entertainment and the like of users. With the continuous development of software service, the software also needs to be updated iteratively, so that the software can be tested in order to ensure that stable and reliable service can be provided for users.
In the related art, a tester can test the software to be tested based on the test case to obtain a test result of the software to be tested. In addition, a code coverage result of the software to be tested in the test process can be obtained, and the code coverage result can include the code coverage ratio (namely code coverage rate) of the software to be tested, so that the function of the software to be tested is perfected based on the code coverage result, and the reliability of the software to be tested is improved.
Disclosure of Invention
The embodiment of the invention aims to provide a code coverage result generation method and a code coverage result generation device, so as to obtain an incremental code coverage result and reduce the acquisition cost of the incremental code coverage result. The specific technical scheme is as follows:
in a first aspect, to achieve the above object, an embodiment of the present invention discloses a method for generating a code coverage result, where the method includes:
in the process of testing the software to be tested based on a preset test case, when the condition that the preset condition is met is detected, acquiring a total code coverage result corresponding to a currently executed test case;
obtaining an incremental code corresponding to a currently executed test case;
and obtaining a current incremental code coverage result based on the full-amount code coverage result and the incremental code.
Optionally, in the process of testing the software to be tested based on the preset test case, when it is detected that the preset condition is met, obtaining a full code coverage result corresponding to the currently executed test case includes:
in the process of testing software to be tested based on a preset test case, when detecting that a component for acquiring incremental coverage is triggered, acquiring a full code coverage result corresponding to a currently executed test case;
alternatively, the first and second electrodes may be,
in the process of testing the software to be tested based on the preset test case, when the specified time is reached, a full code coverage result corresponding to the currently executed test case is obtained.
Optionally, after obtaining a current incremental code coverage result based on the full code coverage result and the incremental code, the method further includes:
the current delta code overlay result is displayed.
Optionally, the displaying the current delta code coverage result includes:
based on the addition of the current incremental code coverage result to a preset Django template, generating a page for displaying the current incremental code coverage result, and displaying a link of the page;
and when detecting that the link of the page is triggered, displaying the page.
Optionally, the obtaining of the incremental code corresponding to the currently executed test case includes:
acquiring the current version number and the baseline version number of the software to be tested;
respectively acquiring a current code corresponding to the current version number and a baseline code corresponding to the baseline version number from a preset path;
and obtaining the incremental code corresponding to the currently executed test case by comparing the current code with the baseline code.
Optionally, the full code coverage result includes an identifier indicating whether each line of code is covered;
the obtaining a current incremental code coverage result based on the full-size code coverage result and the incremental code comprises:
determining, based on the identification, code from the delta code that is to be overwritten as target code;
based on the object code, a current delta code coverage result is generated.
Optionally, the generating a current incremental code coverage result based on the target code includes:
calculating the proportion of the target code in the incremental code as the coverage rate of the incremental code;
generating a current incremental code coverage result; wherein the current incremental code coverage result comprises the incremental code coverage rate and the identification of the incremental code.
In a second aspect, in order to achieve the above object, an embodiment of the present invention discloses an apparatus for generating a code coverage result, where the apparatus includes:
the system comprises a total code coverage result acquisition module, a total code coverage result processing module and a total code coverage result processing module, wherein the total code coverage result acquisition module is used for acquiring a total code coverage result corresponding to a currently executed test case when a preset condition is detected to be met in the process of testing software to be tested based on a preset test case;
the incremental code acquisition module is used for acquiring the incremental code corresponding to the currently executed test case;
and the increment code coverage result acquisition module is used for acquiring a current increment code coverage result based on the full code coverage result and the increment code.
Optionally, the full code coverage result obtaining module is specifically configured to, in a process of testing software to be tested based on a preset test case, obtain a full code coverage result corresponding to a currently executed test case when detecting that a component for obtaining an incremental coverage rate is triggered;
alternatively, the first and second electrodes may be,
in the process of testing the software to be tested based on the preset test case, when the specified time is reached, a full code coverage result corresponding to the currently executed test case is obtained.
Optionally, the apparatus further comprises:
and the display module is used for displaying the current increment code coverage result after the current increment code coverage result is obtained based on the full code coverage result and the increment code.
Optionally, the display module is specifically configured to generate a page for displaying the current incremental code coverage result based on adding the current incremental code coverage result to a preset Django template, and display a link of the page;
and when detecting that the link of the page is triggered, displaying the page.
Optionally, the incremental code obtaining module is specifically configured to obtain a current version number and a baseline version number of the software to be tested;
respectively acquiring a current code corresponding to the current version number and a baseline code corresponding to the baseline version number from a preset path;
and obtaining the incremental code corresponding to the currently executed test case by comparing the current code with the baseline code.
Optionally, the full code coverage result includes an identifier indicating whether each line of code is covered;
the incremental code coverage result acquisition module comprises:
a target code determination submodule for determining, based on the identification, a code to be overwritten from the incremental code as a target code;
and the increment code coverage result generation submodule is used for generating a current increment code coverage result based on the target code.
Optionally, the incremental code coverage result generation submodule is specifically configured to calculate a proportion of the target code in the incremental code, and use the proportion as an incremental code coverage rate;
generating a current delta code coverage result; wherein the current incremental code coverage result comprises the incremental code coverage rate and the identification of the incremental code.
In another aspect of the implementation of the present invention, in order to achieve the above object, an embodiment of the present invention further discloses an electronic device, where the electronic device includes a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete mutual communication through the communication bus;
the memory is used for storing a computer program;
the processor is configured to implement the code coverage result generating method according to any one of the above methods when executing the program stored in the memory.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium, in which a computer program is stored, and the computer program, when executed by a processor, implements the code coverage result generation method as described in any one of the above.
Embodiments of the present invention further provide a computer program product including instructions, which when run on a computer, cause the computer to execute any one of the above-described code coverage result generation methods.
The embodiment of the invention has the following beneficial effects:
the code coverage result generation method provided by the embodiment of the invention can be used for acquiring the full code coverage result corresponding to the currently executed test case when the preset condition is met in the process of testing the software to be tested based on the preset test case; obtaining an incremental code corresponding to a currently executed test case; and obtaining a current incremental code coverage result based on the full code coverage result and the incremental code. Therefore, the incremental code coverage result can be directly obtained, and the acquisition cost of the incremental code coverage result is reduced.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other embodiments can be obtained by using the drawings without creative efforts.
Fig. 1 is a flowchart of a method for generating a code coverage result according to an embodiment of the present invention;
FIG. 2 is a flowchart of another method for generating code coverage results according to an embodiment of the present invention;
FIG. 3 is a flowchart of another method for generating code coverage results according to an embodiment of the present invention;
FIG. 4 is a flowchart of another method for generating code coverage results according to an embodiment of the present invention;
FIG. 5 is a flowchart of another method for generating code coverage results according to an embodiment of the present invention;
FIG. 6 is a flowchart of another method for generating code coverage results according to an embodiment of the present invention;
FIG. 7 is a block diagram of a code coverage result generating apparatus according to an embodiment of the present invention;
fig. 8 is a structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived from the embodiments of the present invention by those skilled in the art based on the description, are within the scope of the present invention.
In the related art, when testing software to be tested based on a testing tool, a tester can only manually open a testing result folder generated by the testing tool (for example, Jenkins (an open source software project, which is a continuous integration tool developed based on Java and is used for monitoring continuous and repeated work and aiming at providing an open and easy-to-use software platform to enable continuous integration of software)) and view a generated code coverage result. In addition, only the full code coverage result is recorded in the test result folder. If the test personnel needs to obtain the incremental code coverage result, statistics needs to be manually carried out on the basis of the full code coverage result recorded in the test result folder, and the labor cost is increased.
In order to solve the above problem, an embodiment of the present invention provides a method for generating a code coverage result, where the method may be applied to an electronic device, and specifically, the electronic device is configured to generate a corresponding code coverage result when testing software to be tested. Referring to fig. 1, fig. 1 is a flowchart of a method for generating a code coverage result according to an embodiment of the present invention, where the method may include the following steps:
s101: in the process of testing the software to be tested based on the preset test case, when the condition that the preset condition is met is detected, a full code coverage result corresponding to the currently executed test case is obtained.
S102: and acquiring the incremental code corresponding to the currently executed test case.
S103: and obtaining a current incremental code coverage result based on the full-amount code coverage result and the incremental code.
The code coverage result generation method provided by the embodiment of the invention can directly obtain the incremental code coverage result, and can reduce the acquisition cost of the incremental code coverage result compared with the incremental code coverage result obtained by manual statistics in the related technology.
For step S101, the preset test case may be set by a tester based on a requirement, and is used to test the function of the software to be tested. For example, the user login function, the fund payment function and the like of the software to be tested can be tested based on the preset test case.
For step S102, one test case may correspond to a code that implements one function, or may also correspond to a code that implements multiple functions. Furthermore, when the preset condition is met, the currently executed test case can be determined, and the incremental code is determined from the corresponding code.
In one embodiment, a full code coverage result corresponding to a currently executed test case may be obtained based on a preset code coverage statistical tool. For example, the pre-set code coverage statistics tool may be Jacoco (providing code coverage statistics for code run based on JVM, it is desirable to provide a lightweight, scalable, documentary library file to integrate various types of build and development tools). Correspondingly, the Jacoco plug-in can be installed in the software to be tested, and further, in the process of testing the software to be tested, the Jacoco service can be started to obtain a full code coverage result.
In one embodiment, the step S101 may include any one of the following steps:
the method comprises the following steps: in the process of testing the software to be tested based on the preset test case, when detecting that the component for acquiring the incremental coverage rate is triggered, acquiring a full code coverage result corresponding to the currently executed test case.
Step two: in the process of testing the software to be tested based on the preset test case, when the specified time is reached, a full code coverage result corresponding to the currently executed test case is obtained.
In the embodiment of the invention, the full code coverage result corresponding to the currently executed test case can be acquired in different modes according to the needs of testers.
In one implementation, the incremental code coverage result can be obtained by combining Jenkins jobof a Jenkins platform based on a Django (a development framework for developing web application) framework.
Illustratively, a tester can set the creation time (namely, the designated time) of the Jenkins joba for acquiring the incremental code coverage result according to the requirement, and then, when the designated time is reached, the Jenkins joba can be started to acquire the incremental code coverage result.
In addition, in one embodiment, a component (which may be referred to as a target component) for acquiring the incremental coverage rate may be set based on the Django framework, and accordingly, when the tester needs to acquire the current incremental code coverage result, a trigger instruction for the target component may be input. Furthermore, when the target component is detected to be triggered, it can be determined that a preset condition is met, a full code coverage result and an incremental code corresponding to a currently executed test case are obtained, and a current incremental code coverage result is obtained, so that the incremental code coverage result is obtained in real time.
In one embodiment, referring to fig. 2, on the basis of fig. 1, after step S103, the method may further include the steps of:
s104: the current delta code overlay result is displayed.
In the implementation of the invention, after the current incremental code coverage result is obtained, the current incremental code coverage result can be directly displayed.
In one embodiment, referring to fig. 3, on the basis of fig. 2, the step S104 may include the following steps:
s1041: and generating a page for displaying the current incremental code coverage result based on adding the current incremental code coverage result to a preset Django template, and displaying a link of the page.
S1042: when detecting that the link of the page is triggered, displaying the page.
In the embodiment of the invention, the software to be tested can be tested based on the Django framework, correspondingly, after the current incremental code coverage result is obtained, the current incremental code coverage result can be added into the preset Django template, and a page for displaying the current incremental code coverage result can be generated.
Further, a link of the page may be displayed, and accordingly, when the tester clicks the link, the tester may jump to display the page, that is, display a current incremental code coverage result included in the page.
Based on the processing, the user can conveniently view the current incremental code coverage result.
In one embodiment, referring to fig. 4, on the basis of fig. 1, the step S102 may include the following steps:
s1021: and acquiring the current version number and the baseline version number of the software to be tested.
S1022: and respectively acquiring a current code corresponding to the current version number and a baseline code corresponding to the baseline version number from the preset path.
S1023: and obtaining the incremental code corresponding to the currently executed test case by comparing the current code with the baseline code.
The current version number may be a current version number of the software to be tested, and the baseline version number may be a historical version number of the software to be tested. The version number may be indicated by Commit ID. The difference between the code corresponding to the current version number and the code corresponding to the baseline version number is the delta code. The preset path is used for storing a code corresponding to the software to be tested.
Illustratively, the difference between the current code and the baseline code, i.e., the delta code of the current version number relative to the baseline version number, may be determined based on a Git diff instruction at the root directory of the Git repository, and then the delta code corresponding to the currently executed test case may be determined from the difference.
In one embodiment, the full code coverage result includes an identifier indicating whether each line of code is covered, and accordingly, referring to fig. 5, the step S103 may include the following steps:
s1031: based on the identification, the code that is overlaid is determined from the delta code as the target code.
S1032: based on the target code, a current delta code overlay result is generated.
In the embodiment of the present invention, an identifier indicating whether each line of code is covered is recorded in a test result folder obtained based on a test tool (e.g., Jenkins).
Furthermore, after the incremental codes corresponding to the currently executed test cases are determined, the codes with the corresponding identifiers representing the coverage can be determined from the incremental codes, and the target codes are obtained.
Then, a current delta code overlay result may be generated based on the target code.
In one implementation, the target code may be directly used as the current incremental code overlay result.
In one embodiment, referring to fig. 6, the step S1032 may include the following steps:
s10321: and calculating the proportion of the target code in the incremental code to serve as the coverage rate of the incremental code.
S10322: current delta code coverage results are generated. And the current incremental code coverage result comprises the incremental code coverage rate and the identification of the incremental code.
In the embodiment of the invention, after the target code is determined, the proportion of the target code in the incremental code can be calculated to obtain the coverage rate of the incremental code.
Further, an incremental code coverage result may be generated that includes the incremental code coverage and the identification of the incremental code.
Accordingly, the generated coverage result of the incremental code can be displayed, so that a tester can directly check the coverage rate of the incremental code, and the covered code and the uncovered code in the incremental code.
Based on the same inventive concept, an embodiment of the present invention further provides a code coverage result generating apparatus, referring to fig. 7, where fig. 7 is a structural diagram of the code coverage result generating apparatus provided in the embodiment of the present invention, and the apparatus may include:
a full code coverage result obtaining module 701, configured to, in a process of testing software to be tested based on a preset test case, obtain a full code coverage result corresponding to a currently executed test case when it is detected that a preset condition is met;
an incremental code obtaining module 702, configured to obtain an incremental code corresponding to a currently executed test case;
an incremental code coverage result obtaining module 703 is configured to obtain a current incremental code coverage result based on the full code coverage result and the incremental code.
Optionally, the full code coverage result obtaining module 701 is specifically configured to, in a process of testing software to be tested based on a preset test case, obtain a full code coverage result corresponding to a currently executed test case when detecting that an assembly for obtaining an incremental coverage rate is triggered;
alternatively, the first and second electrodes may be,
in the process of testing the software to be tested based on the preset test case, when the specified time is reached, a full code coverage result corresponding to the currently executed test case is obtained.
Optionally, the apparatus further comprises:
and the display module is used for displaying the current increment code coverage result after the current increment code coverage result is obtained based on the full code coverage result and the increment code.
Optionally, the display module is specifically configured to generate a page for displaying the current incremental code coverage result based on adding the current incremental code coverage result to a preset Django template, and display a link of the page;
and when detecting that the link of the page is triggered, displaying the page.
Optionally, the incremental code obtaining module 702 is specifically configured to obtain a current version number and a baseline version number of the software to be tested;
respectively acquiring a current code corresponding to the current version number and a baseline code corresponding to the baseline version number from a preset path;
and obtaining the incremental code corresponding to the currently executed test case by comparing the current code with the baseline code.
Optionally, the full code coverage result includes an identifier indicating whether each line of code is covered;
the incremental code coverage result obtaining module 703 includes:
a target code determination submodule for determining, based on the identification, a code to be overwritten from the incremental code as a target code;
and the increment code coverage result generation submodule is used for generating a current increment code coverage result based on the target code.
Optionally, the incremental code coverage result generation submodule is specifically configured to calculate a proportion of the target code in the incremental code, and use the proportion as an incremental code coverage rate;
generating a current delta code coverage result; wherein the current incremental code coverage result comprises the incremental code coverage rate and the identification of the incremental code.
An embodiment of the present invention further provides an electronic device, as shown in fig. 8, which includes a processor 801, a communication interface 802, a memory 803, and a communication bus 804, where the processor 801, the communication interface 802, and the memory 803 complete mutual communication through the communication bus 804,
a memory 803 for storing a computer program;
the processor 801 is configured to implement the following steps when executing the program stored in the memory 803:
in the process of testing software to be tested based on a preset test case, when the condition that the preset condition is met is detected, acquiring a full code coverage result corresponding to a currently executed test case;
obtaining an incremental code corresponding to a currently executed test case;
and obtaining a current incremental code coverage result based on the full code coverage result and the incremental code.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, a computer-readable storage medium is further provided, in which a computer program is stored, and the computer program, when executed by a processor, implements the steps of any of the above-mentioned server testing methods.
In a further embodiment provided by the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any of the server testing methods of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that includes one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, the computer-readable storage medium, and the computer program product embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (16)

1. A method for generating code coverage results, the method comprising:
in the process of testing software to be tested based on a preset test case, when the condition that the preset condition is met is detected, acquiring a full code coverage result corresponding to a currently executed test case;
obtaining an incremental code corresponding to a currently executed test case;
and obtaining a current incremental code coverage result based on the full code coverage result and the incremental code.
2. The method according to claim 1, wherein the obtaining of the full code coverage result corresponding to the currently executed test case when it is detected that a preset condition is met in the process of testing the software to be tested based on the preset test case comprises:
in the process of testing software to be tested based on a preset test case, when detecting that a component for acquiring incremental coverage is triggered, acquiring a full code coverage result corresponding to a currently executed test case;
alternatively, the first and second electrodes may be,
in the process of testing the software to be tested based on the preset test case, when the specified time is reached, a full code coverage result corresponding to the currently executed test case is obtained.
3. The method of claim 1, wherein after obtaining a current delta code coverage result based on the full code coverage result and the delta code, the method further comprises:
the current delta code overlay result is displayed.
4. The method of claim 3, wherein displaying the current delta code overlay result comprises:
based on the fact that the current incremental code coverage result is added into a preset Django template, a page used for displaying the current incremental code coverage result is generated, and a link of the page is displayed;
and when detecting that the link of the page is triggered, displaying the page.
5. The method of claim 1, wherein obtaining delta code corresponding to a currently executed test case comprises:
acquiring the current version number and the baseline version number of the software to be tested;
respectively acquiring a current code corresponding to the current version number and a baseline code corresponding to the baseline version number from a preset path;
and obtaining the incremental code corresponding to the currently executed test case by comparing the current code with the baseline code.
6. The method of claim 1, wherein the full amount code coverage result comprises an indication of whether each line of code is covered;
the obtaining a current incremental code coverage result based on the full-size code coverage result and the incremental code comprises:
determining, based on the identification, code from the delta code that is to be overwritten as target code;
based on the target code, a current delta code overlay result is generated.
7. The method of claim 6, wherein generating a current delta code overlay result based on the object code comprises:
calculating the proportion of the target code in the incremental code to be used as the coverage rate of the incremental code;
generating a current delta code coverage result; wherein the current incremental code coverage result comprises the incremental code coverage rate and the identification of the incremental code.
8. An apparatus for generating code coverage results, the apparatus comprising:
the system comprises a total code coverage result acquisition module, a total code coverage result processing module and a total code coverage result processing module, wherein the total code coverage result acquisition module is used for acquiring a total code coverage result corresponding to a currently executed test case when a preset condition is detected to be met in the process of testing software to be tested based on a preset test case;
the incremental code acquisition module is used for acquiring the incremental code corresponding to the currently executed test case;
and the increment code coverage result acquisition module is used for acquiring a current increment code coverage result based on the full code coverage result and the increment code.
9. The apparatus according to claim 8, wherein the full code coverage result obtaining module is specifically configured to, in a process of testing software to be tested based on a preset test case, obtain a full code coverage result corresponding to a currently executed test case when it is detected that a component for obtaining an incremental coverage is triggered;
alternatively, the first and second electrodes may be,
in the process of testing the software to be tested based on the preset test case, when the specified time is reached, the full code coverage result corresponding to the currently executed test case is obtained.
10. The apparatus of claim 8, further comprising:
and the display module is used for displaying the current increment code coverage result after the current increment code coverage result is obtained based on the full code coverage result and the increment code.
11. The apparatus according to claim 10, wherein the display module is specifically configured to generate a page for displaying the current incremental code coverage result based on adding the current incremental code coverage result to a preset Django template, and display a link of the page;
and when detecting that the link of the page is triggered, displaying the page.
12. The apparatus according to claim 8, wherein the incremental code obtaining module is specifically configured to obtain a current version number and a baseline version number of the software to be tested;
respectively acquiring a current code corresponding to the current version number and a baseline code corresponding to the baseline version number from a preset path;
and obtaining the incremental code corresponding to the currently executed test case by comparing the current code with the baseline code.
13. The apparatus of claim 8, wherein the full code coverage result comprises an indication of whether each line of code is covered;
the incremental code coverage result obtaining module comprises:
a target code determination submodule for determining, based on the identification, a code to be overwritten from the incremental code as a target code;
and the increment code coverage result generation submodule is used for generating a current increment code coverage result based on the target code.
14. The apparatus according to claim 13, wherein the incremental code coverage result generation submodule is specifically configured to calculate a proportion of the target code in the incremental code as an incremental code coverage rate;
generating a current delta code coverage result; wherein the current incremental code coverage result comprises the incremental code coverage rate and the identification of the incremental code.
15. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1 to 7 when executing a program stored in the memory.
16. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 7.
CN202110314432.XA 2021-03-24 2021-03-24 Code coverage result generation method and device Pending CN115129575A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110314432.XA CN115129575A (en) 2021-03-24 2021-03-24 Code coverage result generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110314432.XA CN115129575A (en) 2021-03-24 2021-03-24 Code coverage result generation method and device

Publications (1)

Publication Number Publication Date
CN115129575A true CN115129575A (en) 2022-09-30

Family

ID=83374097

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110314432.XA Pending CN115129575A (en) 2021-03-24 2021-03-24 Code coverage result generation method and device

Country Status (1)

Country Link
CN (1) CN115129575A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117112398A (en) * 2023-07-11 2023-11-24 贝壳找房(北京)科技有限公司 Incremental code coverage rate detection method and device, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117112398A (en) * 2023-07-11 2023-11-24 贝壳找房(北京)科技有限公司 Incremental code coverage rate detection method and device, electronic equipment and storage medium
CN117112398B (en) * 2023-07-11 2024-04-16 贝壳找房(北京)科技有限公司 Incremental code coverage rate detection method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN108683562B (en) Anomaly detection positioning method and device, computer equipment and storage medium
CN114546738B (en) Universal test method, system, terminal and storage medium for server
CN111522728A (en) Method for generating automatic test case, electronic device and readable storage medium
CN113448854A (en) Regression testing method and device
CN111654495B (en) Method, apparatus, device and storage medium for determining traffic generation source
CN106557419B (en) Program testing method and device
CN111221727A (en) Test method, test device, electronic equipment and computer readable medium
CN111858354A (en) Method and device for automatically generating test report, storage medium and electronic equipment
CN110134583B (en) Software testing and data processing method and device
CN114371974A (en) Buried point data checking method and electronic equipment
CN115129575A (en) Code coverage result generation method and device
CN112988589A (en) Interface testing method, device and system
CN105912467B (en) Performance test method and device
CN111858377A (en) Quality evaluation method and device for test script, electronic device and storage medium
CN116738091A (en) Page monitoring method and device, electronic equipment and storage medium
CN111382071A (en) User behavior data testing method and system
CN116016270A (en) Switch test management method and device, electronic equipment and storage medium
CN113282496B (en) Automatic interface testing method, device, equipment and storage medium
CN113220586A (en) Automatic interface pressure test execution method, device and system
CN113377648A (en) Software system diagnosis method and device, electronic equipment and computer readable medium
CN113688134A (en) Visual variable management method, system and equipment based on multidimensional data
CN109165127B (en) Problem interface positioning method and device and electronic equipment
US20160275002A1 (en) Image capture in application lifecycle management for documentation and support
CN111045983A (en) Nuclear power station electronic file management method and device, terminal equipment and medium
CN111949549A (en) Test request screening method, system, electronic device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination