CN103631707A - Method and device for obtaining code coverage rate - Google Patents

Method and device for obtaining code coverage rate Download PDF

Info

Publication number
CN103631707A
CN103631707A CN201210308060.0A CN201210308060A CN103631707A CN 103631707 A CN103631707 A CN 103631707A CN 201210308060 A CN201210308060 A CN 201210308060A CN 103631707 A CN103631707 A CN 103631707A
Authority
CN
China
Prior art keywords
code
coverage rate
file
acquiring
obtaining
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.)
Granted
Application number
CN201210308060.0A
Other languages
Chinese (zh)
Other versions
CN103631707B (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201210308060.0A priority Critical patent/CN103631707B/en
Publication of CN103631707A publication Critical patent/CN103631707A/en
Application granted granted Critical
Publication of CN103631707B publication Critical patent/CN103631707B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and device for obtaining the code coverage rate, and relates to the technical field of communication. The code coverage rate of manual test can be obtained, and consumption of a large number of manpower and material resources is avoided. The method comprises the steps that second codes are obtained after codes with the code coverage rate being obtained are added to first codes of a tested application, and information, recorded in a compiling process of the second codes, of the first codes is used for generating first files; test cases operate after test instructions are received, and code executing information, recorded in an operation process of the test cases, of the first codes is used for generating second files; according to the first files, the second files and code files for obtaining the code coverage rate, the code coverage rate of the first codes is obtained. The method and device for obtaining the code coverage rate are suitable for being adopted when the code coverage rate is obtained by conducting manual test.

Description

Method and device for obtaining code coverage rate
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for obtaining code coverage.
Background
The code coverage rate reflects an important index of the coverage degree of the test case on the tested software, and is a reference value used for measuring the test integrity, and the value of the reference value is equal to the code to which the test runs divided by the total code. With the code coverage data, it can be evaluated whether the test is sufficient.
Currently, a test project is established on the basis of engineering of an Application program (APP) to be tested, wherein an EMMA or similar code coverage statistical tool is added on the basis of the test project, and then a large number of automated test cases are written in the test project. After a large number of test cases written according to the test plan are run, the current code coverage can be obtained.
The inventor finds that at least the following problems exist in the prior art: the functions of the conventional android platform are mainly guaranteed by manual testing, so that the coverage rate of manual testing codes cannot be obtained; in addition, a large amount of automatic test cases need to be written when the code coverage rate is obtained, and a large amount of manpower and material resources are consumed.
Disclosure of Invention
The embodiment of the invention provides a method and a device for acquiring code coverage rate, which can acquire the code coverage rate of a manual test and avoid consuming a large amount of manpower and material resources.
In one aspect, an embodiment of the present invention provides a method for obtaining code coverage, including:
acquiring a second code obtained by adding a code for acquiring code coverage rate in a first code of an application program APP to be tested, and generating a first file from information of the first code recorded in the process of compiling the second code;
after receiving a test instruction, running a test case, and generating a second file from code execution information of the first code recorded in the process of running the test case;
and acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate.
In another embodiment of the present invention, after the obtaining the code coverage of the first code, the method further includes: acquiring a new test sample written by analyzing the first code which is not covered; and after receiving a test instruction, running the new test case, and acquiring the accumulated code coverage rate of the first code according to the method for acquiring the code coverage rate of the first code.
In another embodiment of the present invention, the obtaining the code coverage of the first code comprises: receiving a command for executing a file in a first directory; and executing the command according to the first file and the second file which are arranged in the first directory and the code file for acquiring the code coverage rate, and acquiring the code coverage rate of the first code.
In another embodiment of the present invention, the obtaining the second code obtained by adding the code for obtaining the code coverage rate to the first code of the application program APP to be tested includes:
receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; or,
the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
In another embodiment of the present invention, the information of the first code includes version information of the code, package, class method, and information of a line where the code is located.
In another embodiment of the present invention, the executing the test case after receiving the test instruction, and generating the code execution information of the first code recorded in the process of executing the test case into the second file includes:
after receiving a test instruction, running a test case, recording code execution information of the first code executed in the process of running the test case, and storing the code execution information in an internal memory;
when the APP is cancelled or quitted, calling the code for obtaining the code coverage rate, storing the code execution information stored in the memory in a second file, and deleting the code execution information in the memory.
In another aspect, an embodiment of the present invention provides an apparatus for acquiring code coverage, including:
the code acquiring unit is used for acquiring second codes obtained by adding codes for acquiring the code coverage rate in first codes of the tested application program APP;
a file generation unit for generating a first file from the information of the first code recorded in the process of compiling the second code;
the execution unit is used for running the test case after receiving the test instruction;
the file generating unit is further used for generating a second file from the code execution information of the first code recorded in the process of running the test case;
and the code coverage rate acquiring unit is used for acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate.
In another embodiment of the present invention, the apparatus further comprises:
the test case acquisition unit is used for acquiring a new test case which is compiled after the first code which is not covered is analyzed;
the execution unit is used for running the new test case after receiving the test instruction, and acquiring the accumulated code coverage rate of the first code by the operation of the file generation unit and the code coverage rate acquisition unit.
In another embodiment of the present invention, the code coverage acquiring unit includes:
the command receiving module is used for receiving a command for executing the files in the first directory;
and the code coverage rate acquisition module is used for executing the command according to the first file and the second file which are arranged in the first directory and the code file for acquiring the code coverage rate, and acquiring the code coverage rate of the first code.
In another embodiment of the present invention, the code acquiring unit is configured to:
receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; or,
the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
In another embodiment of the present invention, the information of the first code includes version information of the code, package, class method, and information of a line where the code is located.
In another embodiment of the present invention, the generating the file unit includes:
the record storage module is used for recording the code execution information of the first code executed in the test case running process and storing the code execution information in the memory;
and the file generation module is used for calling the code for acquiring the code coverage rate when the APP is cancelled or quitted, storing the code execution information stored in the memory in a second file, and deleting the code execution information in the memory.
The embodiment of the invention provides a method and a device for obtaining code coverage rate, wherein a second code obtained by adding a code for obtaining the code coverage rate into a first code of an application program (APP) to be tested is obtained, and a first file is generated by compiling information of the first code recorded in the process of compiling the second code; after receiving a test instruction, running a test case, and generating a second file from code execution information of the first code recorded in the process of running the test case; and acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate. When the prior art is adopted to carry out code coverage rate test, the manual test code coverage rate cannot be obtained; in addition, compared with the fact that a large number of automatic test cases need to be written when the code coverage rate is obtained, and a large amount of manpower and material resources are consumed, the scheme provided by the embodiment of the invention can obtain the manual test code coverage rate by adding the code for obtaining the code coverage rate in the source code of the application program, and avoids the consumption of a large amount of manpower and material resources.
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 for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a flowchart of a method for obtaining code coverage according to embodiment 1 of the present invention;
fig. 2 is a block diagram of an apparatus for obtaining code coverage according to embodiment 1 of the present invention;
fig. 3 is a flowchart of a method for obtaining code coverage according to embodiment 2 of the present invention;
fig. 4 is a block diagram of an apparatus for acquiring code coverage according to embodiment 2 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 by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example 1
An embodiment of the present invention provides a method for obtaining a code coverage rate, where an execution subject of the method is a terminal, for example, an Android device, and as shown in fig. 1, the method includes the following steps:
step 101, acquiring a second code obtained by adding a code for acquiring code coverage rate in a first code of a tested Application program (APP), and generating a first file from information of the first code recorded in a process of compiling the second code;
in this step, the first code refers to a source code of the application APP.
The information of the first code comprises version information, package, class method and information of a line where the code is located. That is, the information of the first code includes version information of the code, a package used, a class method used, and a line on which a certain code is located.
The method comprises the following steps: receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; or,
the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
Step 102, running a test case after receiving a test instruction, and generating a second file from code execution information of the first code recorded in the process of running the test case;
and the tester writes a test case according to the tested APP, and then runs the test case after receiving the test instruction. In actual operation, a tester can manually run test cases according to a test plan.
The method comprises the following steps: after receiving a test instruction, running a test case, recording code execution information of the first code executed in the process of running the test case, and storing the code execution information in an internal memory;
when the APP is cancelled or quitted, calling the code for obtaining the code coverage rate, storing the code execution information stored in the memory in a second file, and deleting the code execution information in the memory.
And 103, acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate.
The method comprises the following steps: receiving a command for executing a file in a first directory;
and executing the command according to the first file and the second file which are arranged in the first directory and the code file for acquiring the code coverage rate, and acquiring the code coverage rate of the first code.
Further, the method also comprises the following steps: acquiring a new test sample written by analyzing the first code which is not covered;
and after receiving a test instruction, running the new test case, and acquiring the accumulated code coverage rate of the first code according to the method for acquiring the code coverage rate of the first code.
The embodiment of the invention provides a method for obtaining code coverage rate, which comprises the steps of adding a code for obtaining the code coverage rate in an APP code, compiling the code, and generating a first file from information of a first code recorded in the process of compiling a second code; after receiving a test instruction, running a test case, and generating a second file from code execution information of the first code recorded in the process of running the test case; and acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate, so that the manual test code coverage rate can be acquired, the consumption of a large amount of manpower and material resources is avoided, and the working efficiency is improved.
An embodiment of the present invention provides a device for obtaining code coverage, which may be a terminal, for example, an Android device, and as shown in fig. 2, the device includes: a code acquisition unit 201, a file generation unit 202, an execution unit 203, a code coverage acquisition unit 204;
a code obtaining unit 201, configured to obtain a second code obtained by adding a code for obtaining a code coverage rate to a first code of an application program APP under test;
further, the code obtaining unit 201 is configured to:
receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; or,
the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
A file generation unit 202, configured to generate a first file from information of the first code recorded in the process of compiling the second code;
the information of the first code comprises version information, package, class method and information of a line where the code is located.
The execution unit 203 is used for running the test case after receiving the test instruction;
the file generating unit 202 is further configured to generate a second file from the code execution information of the first code recorded in the process of running the test case;
further, the generate file unit 202 includes:
the record storage module is used for recording the code execution information of the first code executed in the test case running process and storing the code execution information in the memory;
and the file generation module is used for calling the code for acquiring the code coverage rate when the APP is cancelled or quitted, storing the code execution information stored in the memory in a second file, and deleting the code execution information in the memory.
A code coverage rate obtaining unit 204, configured to obtain a code coverage rate of the first code according to the first file and the second file, and a code file for obtaining the code coverage rate.
Further, the code coverage rate obtaining unit 204 includes:
the command receiving module is used for receiving a command for executing the files in the first directory;
and the code coverage rate acquisition module is used for executing the command according to the first file and the second file which are arranged in the first directory and the code file for acquiring the code coverage rate, and acquiring the code coverage rate of the first code.
The device also comprises a test case acquisition unit, a test case analysis unit and a test case analysis unit, wherein the test case acquisition unit is used for acquiring a new test case which is compiled after the first code which is not covered is analyzed;
the execution unit is used for running the new test case after receiving the test instruction, and acquiring the accumulated code coverage rate of the first code by the operation of the file generation unit and the code coverage rate acquisition unit.
The embodiment of the invention provides a device for obtaining code coverage rate, which is used for obtaining a second code obtained by adding a code for obtaining the code coverage rate in a first code of an application program APP to be tested through a code obtaining unit; a file generation unit for generating a first file from the information of the first code recorded in the process of compiling the second code; the execution unit is used for running the test case after receiving the test instruction; the file generating unit is further used for generating a second file from the code execution information of the first code recorded in the process of running the test case; and the code coverage rate acquiring unit is used for acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate, so that the code coverage rate of a manual test can be acquired, the consumption of a large amount of manpower and material resources is avoided, and the working efficiency is improved.
Example 2
An embodiment of the present invention provides a method for obtaining a code coverage rate, where an execution subject of the method is a terminal, for example, the method may be an Android device, and as shown in fig. 3, the method includes the following steps:
step 301, acquiring a second code obtained by adding a code for acquiring a code coverage rate in a first code of an application program APP to be tested;
in this step, the first code is the source code of the APP. The APP is short for Application, and the APP mostly refers to a third-party Application program of the smart phone. In the embodiment of the invention, the APP can refer to an application program on the Android device.
Further, the second code may be obtained in the following two ways:
the first method is as follows: receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; the function called when the APP is logged out or quitted can be OnDestroy.
The second method comprises the following steps: the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
Step 302, compiling the second code, and generating a first file from the information of the first code recorded in the process of compiling the second code;
this step may recompile the second code using Ant and Emma. Ant is a tool for automatically realizing steps of software compiling, testing, deploying and the like, and is mostly used for software development in a Java environment. Emma is a Java code coverage acquisition tool.
Emma performs instrumentation on the compiled second code file, namely records information of the first code in the process of compiling the second code, wherein the information of the first code comprises version information, package, class method and information of a line where the code is located. That is, information such as version information of the APP source code, a package to be used, a class method to be used, and a line where a certain code is located.
After the processing is completed, a default file with a suffix name of em is generated, i.e. the first file in this step, for example, the first file may be a coverage em file.
Further, the recompiled second code is installed, namely, installed on the Android device.
Step 303, running a test case after receiving a test instruction, and generating a second file from code execution information of the first code recorded in the process of running the test case;
the test case is written by the tester according to the functions of the APP.
In this step: after receiving a test instruction, running a test case, recording code execution information of the first code executed in the process of running the test case, and storing the code execution information in an internal memory; further, Emma records the code execution information of the executed first code in the test execution process and records the code execution information in the memory;
when the APP is cancelled or quitted, calling the code for obtaining the code coverage rate, storing the code execution information stored in the memory in a second file, and deleting the code execution information in the memory. Further, the second file may be a default file with a suffix name of.ec, for example the second file may be coverage.ec.
Step 304, acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate;
in this step, the obtained first file and the second file, and the code file for obtaining the code coverage rate are placed in the same directory, for example, in the first directory, that is, the em file, the ec file, and the emma file are placed in the first directory.
Receiving a command for executing a file in a first directory, according to the first file and the second file which are arranged in the first directory and a code file for acquiring code coverage, executing the command, acquiring the code coverage of the first code, and reporting the code coverage in a generated coverage directory.
The code coverage rate report also comprises an un-called first code, so that a tester and a developer can judge whether the un-called first code is a redundant code or not together, the redundant code is removed, and the size of the APP packet can be reduced.
Step 305, acquiring a new test sample written by analyzing the first code which is not covered;
in actual operation, a tester analyzes codes in the first codes which are not covered according to the obtained code coverage rate, and writes corresponding new test cases so as to more completely cover the functions of the application program.
And step 306, after receiving the test instruction, running the new test case, and acquiring the accumulated code coverage rate of the first code according to the method for acquiring the code coverage rate of the first code.
In this step, after the test instruction is received, the new test case is run, that is, the code coverage of the first code can be obtained according to step 303 and step 304, and in this embodiment, step 303, step 304, step 305, and step 306 can be executed in a loop, that is, the manual test can be continuously performed, so that the code coverage can be accumulated. It should be noted that, when the code coverage is obtained in a loop, the same version of the application program needs to be operated.
The embodiment of the invention provides a method for obtaining code coverage rate, which can obtain the code coverage rate of a first code by adding a second code obtained after obtaining the code coverage rate in a first code of an application program, compiling the second code, running a test case and other operations, and can realize accumulation of the code coverage rate, thereby realizing manual test for obtaining the code coverage rate, avoiding a large amount of manpower and material resources from writing an automatic test case, and improving the working efficiency.
In addition, according to the scheme provided by the embodiment of the invention, the area related to the functional test can be evaluated by using the obtained code coverage rate data through the functional tester, so that a corresponding test case can be designed in a more targeted manner, and the error probability of the uncovered first code is reduced.
The embodiment of the invention provides a device for acquiring code coverage rate, which can be a terminal, for example, an android device. As shown in fig. 4, the apparatus includes: the system comprises a code acquisition unit 401, a file generation unit 402, a record storage module 4021, a file generation module 4022, an execution unit 403, a code coverage rate acquisition unit 404, a command receiving module 4041, a code coverage rate acquisition module 4042 and a test case acquisition unit 405;
a code obtaining unit 401, configured to obtain a second code obtained by adding a code for obtaining a code coverage rate to a first code of an application program APP under test; the first code is the source code of the APP.
Further, the code obtaining unit 401 is configured to:
receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; or,
the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
A file generation unit 402, configured to generate a first file from information of the first code recorded in the process of compiling the second code;
the information of the first code comprises version information, package, class method and information of a line where the code is located. That is, information such as version information of the APP source code, a package to be used, a class method to be used, and a line where a certain code is located.
An execution unit 403, configured to run a test case after receiving the test instruction; the test case is written by the tester according to the functions of the APP.
In the process of running the test case, the file generating unit 402 is further configured to generate a second file from the code execution information of the first code recorded in the process of running the test case;
further, the record saving module 4021 in the file generating unit 402 is configured to record code execution information of the first code executed in the process of running the test case, and save the code execution information in a memory;
the file generation module 4022 in the file generation unit 402 is configured to call the code for obtaining the code coverage rate when the APP logs out or exits, store the code execution information stored in the memory in a second file, and delete the code execution information in the memory.
According to the first file and the second file, and the code file for acquiring the code coverage, a code coverage acquiring unit 404 is configured to acquire the code coverage of the first code.
Further, the command receiving module 4041 in the code coverage obtaining unit 404 is configured to receive a command to execute a file in the first directory;
a code coverage rate obtaining module 4042 in the code coverage rate obtaining unit 404, configured to execute the command according to the first file and the second file placed in the first directory and the code file for obtaining code coverage rate, so as to obtain the code coverage rate of the first code.
Further, in this embodiment, the accumulated code coverage may also be obtained, and the test case obtaining unit 405 is configured to obtain a new test case written after analyzing the first code that is not covered;
the execution unit 403 is configured to execute the new test case after receiving the test instruction, and the file generation unit 402 and the code coverage obtaining unit 404 operate to obtain the accumulated code coverage of the first code.
The embodiment of the invention provides a device for obtaining code coverage rate, which can obtain the code coverage rate of a first code by adding a second code obtained after obtaining the code coverage rate in the first code of an application program, compiling the second code, running a test case and other operations, and can realize accumulation of the code coverage rate, thereby realizing manual test for obtaining the code coverage rate, avoiding a large amount of manpower and material resources from writing an automatic test case, and improving the working efficiency.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (12)

1. A method for obtaining code coverage, comprising:
acquiring a second code obtained by adding a code for acquiring code coverage rate in a first code of an application program APP to be tested, and generating a first file from information of the first code recorded in the process of compiling the second code;
after receiving a test instruction, running a test case, and generating a second file from code execution information of the first code recorded in the process of running the test case;
and acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate.
2. The method of claim 1, further comprising, after the obtaining the code coverage of the first code:
acquiring a new test sample written by analyzing the first code which is not covered;
and after receiving a test instruction, running the new test case, and acquiring the accumulated code coverage rate of the first code according to the method for acquiring the code coverage rate of the first code.
3. The method of claim 1 or 2, wherein the obtaining the code coverage of the first code comprises:
receiving a command for executing a file in a first directory;
and executing the command according to the first file and the second file which are arranged in the first directory and the code file for acquiring the code coverage rate, and acquiring the code coverage rate of the first code.
4. The method according to claim 3, wherein the obtaining of the second code after adding the code for obtaining the code coverage rate to the first code of the application program APP to be tested comprises:
receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; or,
the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
5. The method according to claim 1 or 2, wherein the information of the first code comprises version information of the code, package, class method and information of a line where the code is located.
6. The method of claim 5, wherein the step of executing a test case after receiving the test instruction, and generating a second file from the code information of the first code recorded in the process of executing the test case comprises:
after receiving a test instruction, running a test case, recording code execution information of the first code executed in the process of running the test case, and storing the code execution information in an internal memory;
when the APP is cancelled or quitted, calling the code for obtaining the code coverage rate, storing the code execution information stored in the memory in a second file, and deleting the code execution information in the memory.
7. An apparatus for obtaining code coverage, comprising:
the code acquiring unit is used for acquiring second codes obtained by adding codes for acquiring the code coverage rate in first codes of the tested application program APP;
a file generation unit for generating a first file from the information of the first code recorded in the process of compiling the second code;
the execution unit is used for running the test case after receiving the test instruction;
the file generating unit is further used for generating a second file from the code execution information of the first code recorded in the process of running the test case;
and the code coverage rate acquiring unit is used for acquiring the code coverage rate of the first code according to the first file, the second file and the code file for acquiring the code coverage rate.
8. The apparatus of claim 7, further comprising:
the test case acquisition unit is used for acquiring a new test case which is compiled after the first code which is not covered is analyzed;
the execution unit is used for running the new test case after receiving the test instruction, and acquiring the accumulated code coverage rate of the first code by the operation of the file generation unit and the code coverage rate acquisition unit.
9. The apparatus according to claim 7 or 8, wherein the code coverage obtaining unit comprises:
the command receiving module is used for receiving a command for executing the files in the first directory;
and the code coverage rate acquisition module is used for executing the command according to the first file and the second file which are arranged in the first directory and the code file for acquiring the code coverage rate, and acquiring the code coverage rate of the first code.
10. The apparatus of claim 9, wherein the code obtaining unit is configured to:
receiving code for acquiring code coverage rate added in a function called when logging out or quitting in a first code of an APP to be tested, and acquiring a second code consisting of the first code and the code for acquiring code coverage rate; or,
the method comprises the steps of receiving code coverage rate obtaining code added in a function triggered by clicking a button or a menu for obtaining code coverage rate in first code of an APP to be tested, and obtaining second code formed by the first code and the code for obtaining code coverage rate.
11. The apparatus according to claim 7 or 8, wherein the information of the first code comprises version information of the code, package, class method and information of a line where the code is located.
12. The apparatus of claim 11, wherein the generating the file unit comprises:
the record storage module is used for recording the code execution information of the first code executed in the test case running process and storing the code execution information in the memory;
and the file generation module is used for calling the code for acquiring the code coverage rate when the APP is cancelled or quitted, storing the code execution information stored in the memory in a second file, and deleting the code execution information in the memory.
CN201210308060.0A 2012-08-27 2012-08-27 A kind of method and device for obtaining code coverage Active CN103631707B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210308060.0A CN103631707B (en) 2012-08-27 2012-08-27 A kind of method and device for obtaining code coverage

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210308060.0A CN103631707B (en) 2012-08-27 2012-08-27 A kind of method and device for obtaining code coverage

Publications (2)

Publication Number Publication Date
CN103631707A true CN103631707A (en) 2014-03-12
CN103631707B CN103631707B (en) 2018-01-30

Family

ID=50212792

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210308060.0A Active CN103631707B (en) 2012-08-27 2012-08-27 A kind of method and device for obtaining code coverage

Country Status (1)

Country Link
CN (1) CN103631707B (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105608000A (en) * 2015-12-16 2016-05-25 北京奇虎科技有限公司 Method and device for obtaining code coverage rate data
CN105630670A (en) * 2015-12-16 2016-06-01 北京奇虎科技有限公司 Code coverage rate test method and device
CN105701001A (en) * 2014-11-25 2016-06-22 阿里巴巴集团控股有限公司 Processing method and equipment for test coverage rate
CN105843740A (en) * 2016-03-23 2016-08-10 腾讯科技(深圳)有限公司 Method and device for detecting code compiling result
CN105988926A (en) * 2015-02-13 2016-10-05 腾讯科技(深圳)有限公司 Method and device for processing multi-version test data
CN107423222A (en) * 2017-08-08 2017-12-01 腾讯科技(深圳)有限公司 A kind of method and apparatus for determining test coverage
CN107590066A (en) * 2016-07-08 2018-01-16 广州市动景计算机科技有限公司 Method of testing, equipment and the programmable device of application program
CN108170600A (en) * 2017-12-27 2018-06-15 广州品唯软件有限公司 The coverage rate statistical method of front-end code test, apparatus and system
CN109460357A (en) * 2018-10-19 2019-03-12 北京新能源汽车股份有限公司 Method, device and equipment for testing code coverage rate
CN109542789A (en) * 2018-11-26 2019-03-29 泰康保险集团股份有限公司 A kind of code coverage statistical method and device
US11086759B2 (en) 2018-09-27 2021-08-10 SeaLights Technologies LTD System and method for probe injection for code coverage
US11093374B2 (en) 2016-08-09 2021-08-17 SeaLights Technologies LTD System and method for continuous testing and delivery of software
US11573885B1 (en) 2019-09-26 2023-02-07 SeaLights Technologies LTD System and method for test selection according to test impact analytics
US12124357B2 (en) 2022-12-04 2024-10-22 Sealights Technologies Ltd. System and method for test selection according to test impact analytics

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561777A (en) * 2008-04-14 2009-10-21 中兴通讯股份有限公司 System and method for realizing coverage rate test
CN101706751A (en) * 2009-11-23 2010-05-12 中兴通讯股份有限公司 Method and system for calculating coverage rate of service functions of software
CN102419728A (en) * 2011-11-01 2012-04-18 北京邮电大学 Method for determining software test process sufficiency based on coverage rate quantitative indicators

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561777A (en) * 2008-04-14 2009-10-21 中兴通讯股份有限公司 System and method for realizing coverage rate test
CN101706751A (en) * 2009-11-23 2010-05-12 中兴通讯股份有限公司 Method and system for calculating coverage rate of service functions of software
CN102419728A (en) * 2011-11-01 2012-04-18 北京邮电大学 Method for determining software test process sufficiency based on coverage rate quantitative indicators

Cited By (21)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105701001A (en) * 2014-11-25 2016-06-22 阿里巴巴集团控股有限公司 Processing method and equipment for test coverage rate
CN105988926A (en) * 2015-02-13 2016-10-05 腾讯科技(深圳)有限公司 Method and device for processing multi-version test data
CN105988926B (en) * 2015-02-13 2019-06-07 腾讯科技(深圳)有限公司 The treating method and apparatus of multi version test data
CN105608000B (en) * 2015-12-16 2019-05-31 北京奇虎科技有限公司 Obtain the method and device of code coverage data
CN105630670A (en) * 2015-12-16 2016-06-01 北京奇虎科技有限公司 Code coverage rate test method and device
CN105608000A (en) * 2015-12-16 2016-05-25 北京奇虎科技有限公司 Method and device for obtaining code coverage rate data
CN105843740A (en) * 2016-03-23 2016-08-10 腾讯科技(深圳)有限公司 Method and device for detecting code compiling result
CN107590066A (en) * 2016-07-08 2018-01-16 广州市动景计算机科技有限公司 Method of testing, equipment and the programmable device of application program
US11775416B2 (en) 2016-08-09 2023-10-03 SeaLights Technologies LTD System and method for continuous testing and delivery of software
US11093374B2 (en) 2016-08-09 2021-08-17 SeaLights Technologies LTD System and method for continuous testing and delivery of software
CN107423222B (en) * 2017-08-08 2018-05-22 腾讯科技(深圳)有限公司 A kind of method and apparatus of definite test coverage
CN107423222A (en) * 2017-08-08 2017-12-01 腾讯科技(深圳)有限公司 A kind of method and apparatus for determining test coverage
CN108170600A (en) * 2017-12-27 2018-06-15 广州品唯软件有限公司 The coverage rate statistical method of front-end code test, apparatus and system
US11847041B2 (en) 2018-09-27 2023-12-19 Sealights Technologies Ltd. System and method for probe injection for code coverage
US11086759B2 (en) 2018-09-27 2021-08-10 SeaLights Technologies LTD System and method for probe injection for code coverage
CN109460357B (en) * 2018-10-19 2021-10-29 北京新能源汽车股份有限公司 Method, device and equipment for testing code coverage rate
CN109460357A (en) * 2018-10-19 2019-03-12 北京新能源汽车股份有限公司 Method, device and equipment for testing code coverage rate
CN109542789A (en) * 2018-11-26 2019-03-29 泰康保险集团股份有限公司 A kind of code coverage statistical method and device
US11573885B1 (en) 2019-09-26 2023-02-07 SeaLights Technologies LTD System and method for test selection according to test impact analytics
US12124357B2 (en) 2022-12-04 2024-10-22 Sealights Technologies Ltd. System and method for test selection according to test impact analytics
US12124358B2 (en) 2023-09-28 2024-10-22 SeaLights Technologies LTD System and method for continuous testing and delivery of software

Also Published As

Publication number Publication date
CN103631707B (en) 2018-01-30

Similar Documents

Publication Publication Date Title
CN103631707B (en) A kind of method and device for obtaining code coverage
CN108829593B (en) Code coverage rate calculation and analysis method, device, equipment and storage medium
CN105094783B (en) method and device for testing stability of android application
CN108255729B (en) Mobile phone game automatic testing method and system based on Unity platform
CN107797923B (en) Code coverage rate analysis method and application server
CN110990020A (en) Software compiling method and device, electronic equipment and storage medium
US8140911B2 (en) Dynamic software tracing
US10146658B2 (en) User device power consumption monitoring and analysis
CN104407980A (en) Mobile application automated testing device and method
CN104391795A (en) Method and system for automatically testing coverage rate in distributed system
CN102479084A (en) Method and device for acquiring log by Android terminal
CN104063305A (en) Pressure testing method, device and system for intelligent terminal software
CN107015841B (en) Preprocessing method for program compiling and program compiling device
CN104598274A (en) Automatic instrumentation, compiling and installing method and system
CN105653946A (en) Android malicious behavior detection system based on combined event behavior triggering and detection method of Android malicious behavior detection system
CN107678972B (en) Test case evaluation method and related device
US20130179867A1 (en) Program Code Analysis System
CN108446224B (en) Performance analysis method of application program on mobile terminal and storage medium
US10331543B2 (en) Performance diagnostics via offline replay
CN108829577A (en) A kind of automated testing method of application program capacity
CN110889116A (en) Advertisement blocking method and device and electronic equipment
CN112445692A (en) Case testing method and terminal
CN111400171B (en) Interface testing method, system and device and readable storage medium
EP3304249B1 (en) User device power consumption monitoring and analysis
CN112084108A (en) Test script generation method and device and related components

Legal Events

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