CN110704303B - Method and device for acquiring test coverage information - Google Patents

Method and device for acquiring test coverage information Download PDF

Info

Publication number
CN110704303B
CN110704303B CN201910838983.9A CN201910838983A CN110704303B CN 110704303 B CN110704303 B CN 110704303B CN 201910838983 A CN201910838983 A CN 201910838983A CN 110704303 B CN110704303 B CN 110704303B
Authority
CN
China
Prior art keywords
function
source code
tested
information
preset
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.)
Active
Application number
CN201910838983.9A
Other languages
Chinese (zh)
Other versions
CN110704303A (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.)
Shenzhen Kaiyuan Internet Security Technology Co Ltd
Original Assignee
Shenzhen Kaiyuan Internet Security 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 Shenzhen Kaiyuan Internet Security Technology Co Ltd filed Critical Shenzhen Kaiyuan Internet Security Technology Co Ltd
Priority to CN201910838983.9A priority Critical patent/CN110704303B/en
Publication of CN110704303A publication Critical patent/CN110704303A/en
Application granted granted Critical
Publication of CN110704303B publication Critical patent/CN110704303B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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

Abstract

The application is suitable for the technical field of computers, and provides a method for acquiring test coverage information, which comprises the following steps: acquiring a function test request of a project to be tested; the function test request comprises function identification information corresponding to a function to be tested; determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; running the execution source code to obtain a running result of the execution source code; and obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested. In the method, in the testing link, the statistical test coverage condition can be determined based on the source code information of the preset item to be tested through the pre-inserted second function, and the source codes which are tested and the source codes which are not tested in the item to be tested are known. The testing personnel can adjust the test cases in time based on the test coverage information, and the test process is perfected.

Description

Method and device for acquiring test coverage information
Technical Field
The application belongs to the technical field of computers, and particularly relates to a method and a device for acquiring test coverage information.
Background
After the development of the code is completed, the developer needs to test the code, wherein the comprehensive test of the code is important during the test, and the untested part can be clearly known by acquiring the test coverage of the code. However, the existing method for acquiring test coverage is to use static test data to test, preset all possible test cases, and test the code. However, this method of obtaining test coverage cannot accurately obtain test coverage of the item to be tested.
Disclosure of Invention
The embodiment of the application provides a method and a device for acquiring test coverage information, which can solve the problem that the conventional method for acquiring test coverage cannot accurately acquire the test coverage of a project to be tested.
In a first aspect, an embodiment of the present application provides a method for acquiring test coverage information, including:
acquiring a function test request of a project to be tested; the function test request comprises function identification information corresponding to a function to be tested;
determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; wherein the execution source code comprises a first function for testing the function to be tested and a second function inserted in advance; the second function is used for collecting and counting the execution condition information of the first function;
running the execution source code to obtain a running result of the execution source code; the operation result comprises an operation result of the first function and an operation result of the second function;
and obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested.
Further, the second function comprises an information collection function and a source code line number statistical function; the information collection function is used for collecting function operation information of the first function;
the running the execution source code to obtain a running result of the execution source code includes:
and running the execution source code to obtain the running result of the first function, the running result of the information collection function and the running result of the source code line number statistical function.
Further, before determining the execution source code corresponding to the function identification information based on the corresponding relationship between the preset function identification information and the preset execution source code, the method further includes:
when a project test request corresponding to the project to be tested is obtained, starting a preset detection probe, and obtaining all classes from the source codes of the project to be tested;
and inserting a preset second function into the code corresponding to each class based on a preset instrumentation strategy.
Further, before the step of starting a preset detection probe and obtaining all classes from the source code of the item to be tested when the item test request corresponding to the item to be tested is obtained, the method further includes:
deploying the detection probe on the virtual machine based on preset probe deployment parameters.
Further, before obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested, when obtaining the item test request corresponding to the item to be tested, starting a preset detection probe, and after obtaining all the classes from the source codes of the item to be tested, the method further includes:
acquiring identification information, source code line number information and function information of a class corresponding to each class;
and generating source code information of a preset item to be tested based on the identification information, the source code line number information and the function information.
In a second aspect, an embodiment of the present application provides an obtaining apparatus for testing coverage information, including:
the first acquisition unit is used for acquiring a function test request of the item to be tested; the function test request comprises function identification information corresponding to a function to be tested;
the device comprises a determining unit, a judging unit and a processing unit, wherein the determining unit is used for determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; wherein the execution source code comprises a first function for testing the function to be tested and a second function inserted in advance; the second function is used for collecting and counting the execution condition information of the first function;
the first processing unit is used for operating the execution source code to obtain an operation result of the execution source code; the operation result comprises an operation result of the first function and an operation result of the second function;
and the second processing unit is used for obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested.
Further, the second function comprises an information collection function and a source code line number statistical function; the information collection function is configured to collect function operation information of the first function, and the first processing unit is specifically configured to:
and running the execution source code to obtain the running result of the first function, the running result of the information collection function and the running result of the source code line number statistical function.
Further, the device for acquiring the test coverage information further comprises:
the starting unit is used for starting a preset detection probe when a project test request corresponding to the project to be tested is obtained, and obtaining all classes from the source codes of the project to be tested;
and the inserting unit is used for inserting a preset second function into the code corresponding to each class based on a preset instrumentation strategy.
Further, the device for acquiring the test coverage information further comprises:
and the deployment unit is used for deploying the detection probe on the virtual machine based on preset probe deployment parameters.
Further, the device for acquiring the test coverage information further comprises:
the second acquisition unit is used for acquiring the identification information, the source code line number information and the function information of the class corresponding to each class;
and the generating unit is used for generating the source code information of the preset item to be tested based on the identification information, the source code line number information and the function information.
In a third aspect, an embodiment of the present application provides a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the method for acquiring test coverage information according to the first aspect when executing the computer program.
In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the method for acquiring test coverage information according to the first aspect.
In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a terminal device, causes the terminal device to execute the method for acquiring test coverage information according to any one of the above first aspects.
In the embodiment of the application, a function test request of a project to be tested is obtained; the function test request comprises function identification information corresponding to a function to be tested; determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; running the execution source code to obtain a running result of the execution source code; and obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested. In the method, in the testing link, the statistical test coverage condition can be determined based on the source code information of the preset item to be tested through the pre-inserted second function, and the source codes which are tested and not tested in the item to be tested are known. The testing personnel can adjust the test cases in time based on the obtained test coverage information, and the test process is perfected.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic flow chart of a method for acquiring test coverage information according to a first embodiment of the present application;
FIG. 2 is a schematic flow chart diagram of another method for obtaining test coverage information according to a second embodiment of the present application;
FIG. 3 is a schematic flow chart diagram of another method for obtaining test coverage information according to a third embodiment of the present application;
FIG. 4 is a diagram of a device for testing coverage information according to a fourth embodiment of the present application;
fig. 5 is a schematic diagram of an acquisition apparatus for testing coverage information according to a fifth embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.
Fig. 1 is a schematic flowchart of an acquisition method for test coverage information according to a first embodiment of the present application. The execution subject of the method for acquiring the test coverage information in the embodiment is equipment with the function of acquiring the test coverage information, such as a desktop computer, a server device, and the like. The method for acquiring the test coverage information as shown in fig. 1 may include:
s101: acquiring a function test request of a project to be tested; the function test request comprises function identification information corresponding to the function to be tested.
After a project is developed, a tester needs to test the project, the tester tests the project to be tested by establishing test cases, each test case is a group of test input, execution conditions and expected results compiled for a special target so as to test a certain program path or verify whether a certain specific requirement is met, each test case correspondingly generates a functional test request, the functional test request is used for triggering the function corresponding to the functional test request to be tested, the functional test request comprises functional identification information corresponding to the function to be tested, and each functional identification information corresponds to one function to be tested.
The equipment obtains function test requests of items to be tested, each item to be tested can correspond to a plurality of function test requests, and each function test request corresponds to one function to be tested. The function test request at least comprises function identification information corresponding to the function to be tested, wherein the function test request can be directly submitted to the local terminal equipment by a user or transmitted to the local terminal equipment through other equipment to be obtained.
S102: determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; wherein the execution source code comprises a first function for testing the function to be tested and a second function inserted in advance; the second function is used for collecting and counting the execution condition information of the first function.
The device stores a preset execution source code corresponding to each function to be tested, that is, stores a corresponding relationship between the preset function identification information and the preset execution source code. The preset execution source code is used for processing the acquired function test request, and includes a function required when the function to be tested is tested, that is, a first function, and a second function inserted in advance, where the second function is a function inserted in advance into the first function and used for collecting and counting execution condition information of the first function, and the execution condition information of the first function may include function identification information of a function that the first function has completed executing, a line number of an executed function, and the like.
The device determines an execution source code corresponding to the function identification information, namely, an execution source code for testing the function to be tested, based on the corresponding relationship between the preset function identification information and the preset execution source code.
S103: running the execution source code to obtain a running result of the execution source code; the execution result includes an execution result of the first function and an execution result of the second function.
The equipment runs the execution source code, namely runs the first function and the second function, and runs the first function and the second function to obtain a running result, wherein the running result comprises a running result of the first function and a running result of the second function. The running result of the first function identifies the test result of the function to be tested, and the running result of the second function is the collected and counted execution condition information of the first function.
Further, in order to accurately acquire the execution condition information of the first function, the second function includes an information collection function and a source code line number statistical function; the information collecting function is configured to collect function execution information of the first function, and S103 may include: and running the execution source code to obtain the running result of the first function, the running result of the information collection function and the running result of the source code line number statistical function.
In this embodiment, the second function includes an information collection function and a source code line number statistical function, and the information collection function may obtain relevant information of the currently running first function, including a class to which the currently running first function belongs, function identification information, a function call stack, and the like; the source code line number statistical function may obtain line number information of the code whose execution is completed, for example, the line number where the executed source code is located.
When the device runs the execution source code, the information collection function is executed first, and the class, the function identification information, the function call stack and the like of the currently running first function are obtained, that is, the running result of the information collection function. And after the information collection function is executed, other first functions in the function body of the tested project are continuously executed, and after each first function is executed, the source code line number statistical function is executed to obtain the line number information of the source code which is executed, namely the running result of the source code line number statistical function.
S104: and obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested.
The method comprises the steps of storing source code information of a preset item to be tested in equipment, wherein the source code information of the preset item to be tested comprises all source codes and source code line numbers in the item to be tested and all functions in the item to be tested. And obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested, wherein the test coverage information of the item to be tested comprises the functions and the source codes which are tested in the item to be tested, and can also comprise the source code test completion rate.
In the embodiment of the application, a function test request of a project to be tested is obtained; the function test request comprises function identification information corresponding to a function to be tested; determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; running the execution source code to obtain a running result of the execution source code; and obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested. In the method, in the testing link, the statistical test coverage condition can be determined based on the source code information of the preset item to be tested through the pre-inserted second function, and the source codes which are tested and not tested in the item to be tested are known. The testing personnel can adjust the test cases in time based on the obtained test coverage information, and the test process is perfected.
Fig. 2 is a schematic flow chart of another method for acquiring test coverage information according to a second embodiment of the present application. The execution subject of the method for acquiring the test coverage information in the embodiment is equipment with the function of acquiring the test coverage information, such as a desktop computer, a server device, and the like. In order to accurately set the second function, the present embodiment is different from the first embodiment in S201 to S202, where S203 to S206 in the present embodiment are the same as S101 to S104 in the first embodiment, S201 to S202 may be executed before S204, and S201 to S202 may be executed in parallel with S203 or not, as shown in fig. 2, S201 to S202 are specifically as follows:
s201: and when a project test request corresponding to the project to be tested is obtained, starting a preset detection probe, and obtaining all classes from the source codes of the project to be tested.
The equipment stores a preset detection probe which is a Java probe, namely, a Java agent pile inserting technology. Java agent was introduced in JDK1.5, a technique that can dynamically modify Java bytecodes. Byte codes formed after the java class is compiled are executed by the JVM, and the JVM acquires the byte code information before executing the byte codes and modifies the byte codes to complete some additional functions, namely java agent instrumentation. The java agent instrumentation can intercept and modify the bytecode before loading the java bytecode. The bytecode to be loaded and executed is modified during the jvm run. The method can realize byte code modification at some frames or acquisition points of the technology, monitor the application, or add extra operation when executing a specified method or interface.
The method comprises the steps that a preset detection probe supporting method executes time-consuming range grabbing setting, and a source code running track appearing in a set time-consuming range when a system runs is grabbed according to the time-consuming range; the method supports capturing specific code configuration, facilitates capturing the configured specific method, and filters out the time-consuming situation of executing the related source codes; supporting APP layer entrance method filtering, configuring a method before entrance operation for monitoring, and performing method special analysis, wherein the method is equivalent to the time consumption of a special monitoring method; an entry method parameter output function is supported, and corresponding entry parameters with high time consumption are conveniently tracked; and providing functions of displaying time consumption of a WEB page display interface, displaying a source code calling relation graph, displaying the percentage of time consumption of a method and highlighting a suspicious method.
When the equipment acquires a project test request corresponding to a project to be tested, the project test request corresponding to the project to be tested comprises project identification information of the project to be tested, and the project test request corresponding to the project to be tested is used for triggering the test of the project to be tested. Before the function to be tested is formally tested, the preset detection probe is started, and all classes are obtained from the source code of the project to be tested. A class is a template that describes the behavior and state of a class of objects, and in Java, a class can be viewed as a template for creating Java objects, and a class can have multiple methods. The preset detection probe can filter all classes loaded by the Java JVM virtual machine after being started, and the probe can filter all classes loaded by the Java JVM virtual machine according to the root path of the source code of the item to be tested.
Further, in order to acquire the preset detection probe, before S201, the method may include: deploying the detection probe on the virtual machine based on preset probe deployment parameters.
When the equipment acquires a project test request corresponding to a project to be tested, the project test request corresponding to the project to be tested comprises project identification information of the project to be tested, and the project test request corresponding to the project to be tested is used for triggering the test of the project to be tested. Before formally testing the function to be tested, a detection probe can be deployed on a server of a project operation environment to be tested in a manner of adding a Java agent parameter to a Java JVM virtual machine, and path information in the Java agent parameter points to the detection probe.
S202: and inserting a preset second function into the code corresponding to each class based on a preset instrumentation strategy.
And the equipment inserts a preset second function into the code corresponding to each class based on a preset instrumentation strategy, wherein the process is byte code instrumentation. The byte code instrumentation of java agent is mainly used for modifying byte codes and loading new byte codes.
Fig. 3 is a schematic flow chart of another method for acquiring test coverage information according to a third embodiment of the present application. The execution subject of the method for acquiring the test coverage information in the embodiment is equipment with the function of acquiring the test coverage information, such as a desktop computer, a server device, and the like. In order to accurately obtain the source code information of the item to be tested, and thus accurately obtain the test coverage information, the present embodiment differs from the first embodiment in S306 to S307, where S301 to S305 in the present embodiment are the same as S201 to S205 in the second embodiment, S308 in the present embodiment is the same as S206 in the first embodiment, where S306 to S307 are executed after S301 and before S308, as shown in fig. 3, and S306 to S307 specifically are as follows:
s306: and acquiring identification information, source code line number information and function information of the class corresponding to each class.
The device collects basic information of all classes while performing byte code instrumentation, for example, identification information of the classes, source code line number information, function information, and the like, and all the source code information of the item is obtained after counting the information of each class.
S307: and generating source code information of a preset item to be tested based on the identification information, the source code line number information and the function information.
The device stores the identification information, the source code line number information, the function information and the like of all classes, and generates the source code information of the preset item to be tested, namely the source code information is used as the base number when the test coverage is obtained.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
Referring to fig. 4, fig. 4 is a schematic diagram of a device for testing coverage information according to a fourth embodiment of the present application. The units included are used to perform the steps in the embodiments corresponding to fig. 1-3. Please refer to the related description of the embodiments corresponding to fig. 1 to fig. 3. For convenience of explanation, only the portions related to the present embodiment are shown. Referring to fig. 4, the test coverage information device 4 includes:
a first obtaining unit 410, configured to obtain a function test request of an item to be tested; the function test request comprises function identification information corresponding to a function to be tested;
a determining unit 420, configured to determine, based on a correspondence between preset function identification information and preset execution source codes, execution source codes corresponding to the function identification information; wherein the execution source code comprises a first function for testing the function to be tested and a second function inserted in advance; the second function is used for collecting and counting the execution condition information of the first function;
the first processing unit 430 is configured to run the execution source code, and obtain a running result of the execution source code; the operation result comprises an operation result of the first function and an operation result of the second function;
the second processing unit 440 is configured to obtain test coverage information of the item to be tested based on the operation results of all the second functions and source code information of a preset item to be tested.
Further, the second function comprises an information collection function and a source code line number statistical function; the information collection function is configured to collect function running information of the first function, and the first processing unit 430 is specifically configured to:
and running the execution source code to obtain the running result of the first function, the running result of the information collection function and the running result of the source code line number statistical function.
Further, the acquisition device 4 for testing coverage information further includes:
the starting unit is used for starting a preset detection probe when a project test request corresponding to the project to be tested is obtained, and obtaining all classes from the source codes of the project to be tested;
and the inserting unit is used for inserting a preset second function into the code corresponding to each class based on a preset instrumentation strategy.
Further, the acquisition device 4 for testing coverage information further includes:
and the deployment unit is used for deploying the detection probe on the virtual machine based on preset probe deployment parameters.
Further, the acquisition device 4 for testing coverage information further includes:
the second acquisition unit is used for acquiring the identification information, the source code line number information and the function information of the class corresponding to each class;
and the generating unit is used for generating the source code information of the preset item to be tested based on the identification information, the source code line number information and the function information.
Fig. 5 is a schematic diagram of an acquisition apparatus for testing coverage information according to a fifth embodiment of the present application. As shown in fig. 5, the acquisition apparatus 5 for testing coverage information of this embodiment includes: a processor 50, a memory 51 and a computer program 52 stored in said memory 51 and executable on said processor 50, such as an acquisition program for testing coverage information. The processor 50, when executing the computer program 52, implements the steps in the above-mentioned embodiments of the method for acquiring test coverage information, such as the steps 101 to 104 shown in fig. 1. Alternatively, the processor 50, when executing the computer program 52, implements the functions of the modules/units in the above-mentioned device embodiments, such as the functions of the modules 410 to 440 shown in fig. 4.
Illustratively, the computer program 52 may be partitioned into one or more modules/units, which are stored in the memory 51 and executed by the processor 50 to accomplish the present application. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of the computer program 52 in the acquisition device 5 for testing coverage information. For example, the computer program 52 may be divided into a first acquiring unit, a determining unit, a first processing unit, and a second processing unit, and the specific functions of each unit are as follows:
the first acquisition unit is used for acquiring a function test request of the item to be tested; the function test request comprises function identification information corresponding to a function to be tested;
the device comprises a determining unit, a judging unit and a processing unit, wherein the determining unit is used for determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; wherein the execution source code comprises a first function for testing the function to be tested and a second function inserted in advance; the second function is used for collecting and counting the execution condition information of the first function;
the first processing unit is used for operating the execution source code to obtain an operation result of the execution source code; the operation result comprises an operation result of the first function and an operation result of the second function;
and the second processing unit is used for obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested.
The acquiring device 5 for testing the coverage information may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The acquisition device for testing coverage information may include, but is not limited to, a processor 50, a memory 51. It will be understood by those skilled in the art that fig. 5 is only an example of the acquisition device 5 for testing coverage information, and does not constitute a limitation to the acquisition device 5 for testing coverage information, and may include more or less components than those shown, or some components in combination, or different components, for example, the acquisition device for testing coverage information may further include an input-output device, a network access device, a bus, etc.
The Processor 50 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 51 may be an internal storage unit of the obtaining device 5 for testing coverage information, such as a hard disk or a memory of the obtaining device 5 for testing coverage information. The memory 51 may also be an external storage device of the device 5 for obtaining the test coverage information, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the device 5 for obtaining the test coverage information. Further, the memory 51 may also include both an internal storage unit and an external storage device of the acquisition device 5 of the test coverage information. The memory 51 is used for storing the computer program and other programs and data required by the acquisition device for testing coverage information. The memory 51 may also be used to temporarily store data that has been output or is to be output.
It should be noted that, for the information interaction, execution process, and other contents between the above-mentioned devices/units, the specific functions and technical effects thereof are based on the same concept as those of the embodiment of the method of the present application, and specific reference may be made to the part of the embodiment of the method, which is not described herein again.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
An embodiment of the present application further provides a network device, where the network device includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor, the processor implementing the steps of any of the various method embodiments described above when executing the computer program.
The embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps in the above-mentioned method embodiments.
The embodiments of the present application provide a computer program product, which when running on a mobile terminal, enables the mobile terminal to implement the steps in the above method embodiments when executed.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium and can implement the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code to a photographing apparatus/terminal apparatus, a recording medium, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), an electrical carrier signal, a telecommunications signal, and a software distribution medium. Such as a usb-disk, a removable hard disk, a magnetic or optical disk, etc. In certain jurisdictions, computer-readable media may not be an electrical carrier signal or a telecommunications signal in accordance with legislative and patent practice.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/network device and method may be implemented in other ways. For example, the above-described apparatus/network device embodiments are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implementing, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.

Claims (8)

1. A method for acquiring test coverage information is characterized by comprising the following steps:
acquiring a function test request of a project to be tested; the function test request comprises function identification information corresponding to a function to be tested;
determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; wherein the execution source code comprises a first function for testing the function to be tested and a second function pre-inserted into the first function; the second function is used for collecting and counting the execution condition information of the first function; the second function comprises an information collection function and a source code line number statistical function; the information collection function is used for collecting function operation information of the first function, and comprises a class to which the currently operated first function belongs, function identification information and a function call stack; the source code line number statistical function acquires line number information of the executed code;
running the execution source code to obtain a running result of the execution source code; the running result comprises a running result of the first function and a running result of the second function, and comprises:
running the execution source code to obtain a running result of the first function, a running result of the information collection function and a running result of a source code line number statistical function;
and obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested, wherein the source code information of the preset item to be tested comprises all the source codes and the source code line number in the item to be tested.
2. The method according to claim 1, wherein before determining the execution source code corresponding to the function identification information based on the correspondence between the preset function identification information and the preset execution source code, the method further comprises:
when a project test request corresponding to the project to be tested is obtained, starting a preset detection probe, and obtaining all classes from the source codes of the project to be tested;
and inserting a preset second function into the code corresponding to each class based on a preset instrumentation strategy.
3. The method according to claim 2, wherein before the step of starting a preset detection probe to obtain all classes from the source code of the item to be tested when the item test request corresponding to the item to be tested is obtained, the method further comprises:
deploying the detection probe on the virtual machine based on preset probe deployment parameters.
4. The method according to claim 2, wherein before obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and source code information of a preset item to be tested, when obtaining an item test request corresponding to the item to be tested, starting a preset detection probe, and after obtaining all classes from the source code of the item to be tested, the method further comprises:
acquiring identification information, source code line number information and function information of a class corresponding to each class;
and generating source code information of a preset item to be tested based on the identification information, the source code line number information and the function information.
5. An acquisition device for testing coverage information, comprising:
the first acquisition unit is used for acquiring a function test request of the item to be tested; the function test request comprises function identification information corresponding to a function to be tested;
the device comprises a determining unit, a judging unit and a processing unit, wherein the determining unit is used for determining an execution source code corresponding to the function identification information based on the corresponding relation between the preset function identification information and a preset execution source code; wherein the execution source code comprises a first function for testing the function to be tested and a second function pre-inserted into the first function; the second function is used for collecting and counting the execution condition information of the first function; the second function comprises an information collection function and a source code line number statistical function; the information collection function is used for collecting function operation information of the first function, and comprises a class to which the currently operated first function belongs, function identification information and a function call stack; the source code line number statistical function acquires line number information of the executed code;
the first processing unit is used for operating the execution source code to obtain an operation result of the execution source code; the running result comprises a running result of the first function and a running result of the second function, and comprises:
running the execution source code to obtain a running result of the first function, a running result of the information collection function and a running result of a source code line number statistical function;
and the second processing unit is used for obtaining the test coverage information of the item to be tested based on the operation results of all the second functions and the source code information of the preset item to be tested, wherein the source code information of the preset item to be tested comprises all the source codes and the source code line number in the item to be tested.
6. The apparatus for acquiring test coverage information according to claim 5, further comprising:
the starting unit is used for starting a preset detection probe when a project test request corresponding to the project to be tested is obtained, and obtaining all classes from the source codes of the project to be tested;
and the inserting unit is used for inserting a preset second function into the code corresponding to each class based on a preset instrumentation strategy.
7. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the method according to any of claims 1 to 4 when executing the computer program.
8. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1 to 4.
CN201910838983.9A 2019-09-05 2019-09-05 Method and device for acquiring test coverage information Active CN110704303B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910838983.9A CN110704303B (en) 2019-09-05 2019-09-05 Method and device for acquiring test coverage information

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910838983.9A CN110704303B (en) 2019-09-05 2019-09-05 Method and device for acquiring test coverage information

Publications (2)

Publication Number Publication Date
CN110704303A CN110704303A (en) 2020-01-17
CN110704303B true CN110704303B (en) 2021-07-20

Family

ID=69194330

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910838983.9A Active CN110704303B (en) 2019-09-05 2019-09-05 Method and device for acquiring test coverage information

Country Status (1)

Country Link
CN (1) CN110704303B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111581076A (en) * 2020-03-30 2020-08-25 平安科技(深圳)有限公司 System code testing method and device, computer equipment and storage medium
CN111831549B (en) * 2020-06-04 2023-04-14 深圳手回科技集团有限公司 Incremental code coverage rate determining method, device, equipment and storage medium
CN113132522A (en) * 2021-03-19 2021-07-16 深圳市几米物联有限公司 Test method, device, server and medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102222041A (en) * 2011-06-15 2011-10-19 深圳市运通信息技术有限公司 Test analysis system and method based on embedded software
CN103699476A (en) * 2012-09-27 2014-04-02 腾讯科技(深圳)有限公司 Coverage rate testing method and system
US20150220424A1 (en) * 2014-01-31 2015-08-06 Fujitsu Limited Test double generation

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102222041A (en) * 2011-06-15 2011-10-19 深圳市运通信息技术有限公司 Test analysis system and method based on embedded software
CN103699476A (en) * 2012-09-27 2014-04-02 腾讯科技(深圳)有限公司 Coverage rate testing method and system
US20150220424A1 (en) * 2014-01-31 2015-08-06 Fujitsu Limited Test double generation

Also Published As

Publication number Publication date
CN110704303A (en) 2020-01-17

Similar Documents

Publication Publication Date Title
CN110704303B (en) Method and device for acquiring test coverage information
CN107066390B (en) Dynamic memory leak detection method and system
CN106326067B (en) A kind of method and device that cpu performance is monitored under pressure test
US10599558B1 (en) System and method for identifying inputs to trigger software bugs
EP2063377A1 (en) Method and system for whitelisting software components
CN108920370B (en) Compatibility problem detection method, device and equipment
CN111831573B (en) Method, device, computer system and medium for determining code branch coverage condition
CN110851352A (en) Fuzzy test system and terminal equipment
CN110704311B (en) Application program testing method and device, electronic equipment and readable storage medium
CN112948234A (en) Interface test method and device and electronic equipment
CN112084024B (en) Memory monitoring method, device, medium and electronic equipment
CN109902001B (en) Method for detecting uninitialized variable and terminal equipment
CN111858307B (en) Fuzzy test method and equipment
CN113806231A (en) Code coverage rate analysis method, device, equipment and medium
US9632757B2 (en) Custom class library generation method and apparatus
CN113110870A (en) Resource packaging management method, device, equipment and storage medium
CN114595008A (en) System resource management method and related equipment
CN111078550A (en) Software testing method and device, computer device and storage medium
CN116414722B (en) Fuzzy test processing method and device, fuzzy test system and storage medium
CN111930418B (en) Diagnostic device function configuration method, diagnostic device, and storage medium
CN112363870B (en) Application program development processing method and device, computer equipment and storage medium
CN109446166B (en) Method for detecting file directory, computer readable storage medium and terminal device
CN114491520A (en) Application program protection method and related equipment
CN105528298A (en) Safety testing method and device
CN113204350A (en) Code increment coverage rate statistical method and device, electronic equipment 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
GR01 Patent grant
GR01 Patent grant