CN107015909B - Test method and device based on code change analysis - Google Patents

Test method and device based on code change analysis Download PDF

Info

Publication number
CN107015909B
CN107015909B CN201710211420.8A CN201710211420A CN107015909B CN 107015909 B CN107015909 B CN 107015909B CN 201710211420 A CN201710211420 A CN 201710211420A CN 107015909 B CN107015909 B CN 107015909B
Authority
CN
China
Prior art keywords
class
node
metadata set
target
attribute
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
CN201710211420.8A
Other languages
Chinese (zh)
Other versions
CN107015909A (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.)
Hisense Visual Technology Co Ltd
Original Assignee
Hisense Electric 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 Hisense Electric Co Ltd filed Critical Hisense Electric Co Ltd
Priority to CN201710211420.8A priority Critical patent/CN107015909B/en
Publication of CN107015909A publication Critical patent/CN107015909A/en
Application granted granted Critical
Publication of CN107015909B publication Critical patent/CN107015909B/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/3684Test management for test design, e.g. generating new test cases

Abstract

The invention discloses a testing method and device based on code change analysis, and belongs to the field of computers. The method comprises the following steps: respectively generating a first metadata set and a second metadata set of a tree structure according to a plurality of class files generated by current compilation and a plurality of class files generated by any previous compilation before the current compilation; acquiring a plurality of member functions of which the codes are changed by using the difference analysis of the first metadata set and the second metadata set; and testing based on the test case set generated by the test cases corresponding to the plurality of member functions one by one. The invention can accurately reflect which member functions have code changes, and the test cases selected according to the member functions have strong pertinence, thereby realizing the pertinence test of the member function level and improving the test efficiency.

Description

Test method and device based on code change analysis
Technical Field
The invention relates to the field of computers, in particular to a test method and a test device based on code change analysis.
Background
With the increasingly fierce market competition, the requirement on the speed of product development is higher and higher. Products often need to undergo various tests during the development process. For testing of products, developers generally develop many test cases to cover as many scenarios as possible. In the development process of the product, changes of a source code file may be involved, and at the moment, the changes need to be analyzed, and then test cases are selected to carry out targeted testing based on the analysis result.
Currently, the testing method may include: and automatically monitoring the source code file, if the source code file is changed, if the timestamp of the source code file is changed, considering that the class corresponding to the source code file is changed, and then testing the class, namely screening all test cases corresponding to the class from the test case library, and executing the test cases to finish the test. The class refers to a file generated by compiling the source code file.
In the process of implementing the invention, the inventor finds that the prior art has at least the following problems:
the technology carries out code change analysis by monitoring the source code file, the granularity which can be monitored is limited on the class level, only the class change can be analyzed, which codes in the class are changed cannot be accurately reflected, and the test case selected based on the class has poor pertinence, so that the test efficiency is low.
Disclosure of Invention
In order to solve the problems in the prior art, embodiments of the present invention provide a test method and apparatus based on code change analysis. The technical scheme is as follows:
in a first aspect, a test method based on code change analysis is provided, where the method includes:
according to a plurality of class files generated by current compilation and a plurality of class files generated by any one compilation before the current compilation, a first metadata set and a second metadata set of a tree structure are generated in a distributed mode, wherein the two metadata sets respectively comprise a plurality of class nodes and a plurality of method nodes under the class nodes, each class node corresponds to one class file, and each method node corresponds to one member function;
acquiring a plurality of member functions of which the codes are changed by using the difference analysis of the first metadata set and the second metadata set;
and testing based on the test case set generated by the test cases corresponding to the plurality of member functions one by one.
In a first implementation manner of the first aspect, for the first metadata set and the second metadata set, a generation process of any metadata set includes:
analyzing a plurality of class files generated by compiling to obtain names and summary information of the class files and names and byte code sequences of a plurality of member functions contained in each class file;
and forming a plurality of class nodes based on the names and the summary information of the class files, forming a plurality of method nodes based on the names and the byte code sequences of a plurality of member functions contained in the class files for each class file, and taking the plurality of method nodes as the child nodes of the class nodes corresponding to the class files.
In a second implementation manner of the first aspect, the performing the difference analysis on the first metadata set and the second metadata set specifically includes:
for any class node in the first metadata set, reading the name of the class node, and searching a target class node in the second metadata set, wherein the name of the target class node is the same as that of the class node;
and if the target class node cannot be searched, marking the change attributes of all member functions under the class node as first attributes, wherein the first attributes are used for indicating that code change occurs.
In a third implementation manner of the first aspect, after the target class node is searched in the second metadata set, the method further includes:
if the target class node is found, comparing whether the summary information of the class node is the same as the summary information of the target class node;
if the attribute is the same as the attribute, marking the changed attribute of all member functions under the class node as a second attribute, wherein the second attribute is used for indicating that no code change occurs;
and if the class node is different from the target class node, performing difference analysis on the method node under the class node and the method node under the target class node.
In a fourth implementation manner of the first aspect, the performing difference analysis on the method node under the class node and the method node under the target class node includes:
for each method node under the class node, reading the name of the method node, and searching a target method node in the second metadata set, wherein the name of the target method node is the same as that of the method node;
and if the target method node cannot be found, marking the change attribute of the member function corresponding to the method node as the first attribute.
In a fifth implementation manner of the first aspect, after searching for the target method node in the second metadata set, the method further includes:
if the target method node is found, calculating a Levensstein distance according to the byte code sequence of the method node and the byte code sequence of the target method node;
if the Levensstein distance is larger than or equal to a preset threshold value, marking the change attribute of the member function corresponding to the method node as the first attribute;
and if the Levensstein distance is smaller than a preset threshold value, marking the change attribute of the member function corresponding to the method node as the second attribute.
In a second aspect, a test apparatus based on code change analysis is provided, the apparatus comprising:
the generating module is used for respectively generating a first metadata set and a second metadata set of a tree structure according to a plurality of class files generated by current compilation and a plurality of class files generated by any one compilation before the current compilation, wherein the two metadata sets respectively comprise a plurality of class nodes and a plurality of method nodes under the class nodes, and each method node corresponds to a member function;
the analysis module is used for obtaining a plurality of member functions of which the codes are changed by the difference analysis of the first metadata set and the second metadata set;
and the testing module is used for testing based on the test case set generated by the test cases which are in one-to-one correspondence with the plurality of member functions.
In a first implementation form of the second aspect, the analysis module comprises:
the searching sub-module is used for reading the name of any class node in the first metadata set and searching a target class node in the second metadata set, wherein the name of the target class node is the same as that of the class node;
and the marking submodule is used for marking the change attributes of all member functions under the class node as a first attribute if the target class node cannot be searched, wherein the first attribute is used for indicating that code change occurs.
In a second implementation manner of the second aspect, the search sub-module is further configured to, if the target class node is found and the summary information of the class node is the same as the summary information of the target class node, read a name of the method node for each method node under the class node, and find the target method node in the second metadata set, where the name of the target method node is the same as the name of the method node;
the marking sub-module is further configured to mark a change attribute of the member function corresponding to the method node as the first attribute if the target method node is not found.
In a third implementation form of the second aspect, the analysis module further comprises a computation submodule:
the calculation submodule is used for calculating the Levenstein distance according to the byte code sequence of the method node and the byte code sequence of the target method node if the target method node is found;
the marking sub-module is further configured to mark a change attribute of the member function corresponding to the method node as the first attribute if the levenstein distance is greater than or equal to a preset threshold value;
the marking sub-module is further configured to mark a change attribute of the member function corresponding to the method node as the second attribute if the levenstein distance is smaller than a preset threshold value.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
the method comprises the steps of obtaining a plurality of member functions of which codes are changed by performing difference analysis on class nodes in a first metadata set and class nodes in a second metadata set, further obtaining test cases corresponding to the member functions one by one according to the member functions, and generating a test case set according to the test cases for testing. The technical scheme can accurately reflect which member functions have code changes, the test cases selected according to the member functions have strong pertinence, the member function level pertinence test can be realized, and the test efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a schematic structural diagram of a test system according to an embodiment of the present invention;
FIG. 2 is a flowchart of a test method based on code change analysis according to an embodiment of the present invention;
FIG. 3 is a flowchart of a test method based on code change analysis according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a tree-structured metadata set provided by an embodiment of the present invention;
FIG. 5 is a flowchart of a test method based on code change analysis according to an embodiment of the present invention;
FIG. 6 is a schematic structural diagram of a test apparatus based on code change analysis according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an analysis module 602 according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of another analysis module 602 provided in the embodiment of the present invention;
fig. 9 is a block diagram of a test device based on code change analysis according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Fig. 1 is a schematic structural diagram of a test system according to an embodiment of the present invention. The test system comprises a code compiling unit 101, a class file storage unit 102, a class file library 103, a class file reading unit 104, a class file analyzing unit 105, a test case screening unit 106 and a test case library 107.
The code compiling unit 101 is responsible for compiling work each time, and comprises compiling java files to generate corresponding class files; the class file storage unit 102 is responsible for storing the class file generated by the code compiling unit 101 into a specified directory of the class file library 103; the class file reading unit 104 is responsible for reading the compiled class file from the specified directory for processing by the class file analyzing unit 104; the class file analyzing unit 105 is responsible for analyzing the class file according to the specification of the Java virtual machine to obtain the related information of the class file, and generating a metadata set with a tree structure based on the related information; the test case screening unit 106 is responsible for performing difference analysis on the tree-structure metadata set to obtain member functions of which codes are changed, and then screening test cases corresponding to the member functions from the test case library according to the member functions; the test case library 107 is used to provide a plurality of test cases.
In the embodiments of the present invention described below, the various steps may actually be performed by one or more units of the test system in a cooperative manner, as will be described in the steps of the subsequent embodiments.
Fig. 2 is a flowchart of a test method based on code change analysis according to an embodiment of the present invention. Referring to fig. 2, the method includes:
201. according to a plurality of class files generated by current compilation and a plurality of class files generated by any previous compilation before the current compilation, a first metadata set and a second metadata set of a tree structure are respectively generated, wherein the two metadata sets respectively comprise a plurality of class nodes and a plurality of method nodes under the class nodes, each class node corresponds to one class file, and each method node corresponds to one member function.
202. And acquiring a plurality of member functions of the changed code by using the difference analysis of the first metadata set and the second metadata set.
203. And testing based on the test case set generated by the test cases corresponding to the plurality of member functions one by one.
According to the method provided by the embodiment of the invention, a plurality of member functions with changed codes are obtained by carrying out difference analysis on the class node in the first metadata set and the class node in the second metadata set, and then test cases corresponding to the plurality of member functions one by one are obtained for the plurality of member functions, and the test case set is generated according to the test cases for testing. The technical scheme can accurately reflect which member functions have code changes, the test cases selected according to the member functions have strong pertinence, the member function level pertinence test can be realized, and the test efficiency is improved.
Optionally, for the first metadata set and the second metadata set, the generating process set of any metadata set includes:
analyzing a plurality of class files generated by compiling to obtain the names and summary information of the class files, and the names and byte code sequences of a plurality of member functions contained in each class file;
forming a plurality of class nodes based on the names and the summary information of the class files, forming a plurality of method nodes generated by current compilation based on the names and the byte code sequences of a plurality of member functions contained in the class files for each class file, and taking the plurality of method nodes as child nodes of the class nodes corresponding to the class files;
optionally, the difference analysis with the first metadata set and the second metadata set specifically includes:
for any class node in the first metadata set, reading the name of the class node, and searching a target class node in the second metadata set, wherein the name of the target class node is the same as that of the class node;
if the target class node is not found, the change attribute of all member functions under the class node is marked as a first attribute, and the first attribute is used for indicating that code change occurs.
Optionally, after the target class node is searched in the second metadata set, the method further includes:
if the target class node is found, comparing whether the summary information of the class node is the same as the summary information of the target class node;
if the attribute is the same, marking the change attribute of all methods under the class node as a second attribute, wherein the second attribute is used for indicating that no code change occurs;
and if the class node is different from the target class node, performing difference analysis on the method node under the class node and the method node under the target class node.
Optionally, performing difference analysis on the method node under the class node and the method node under the target class node includes:
for each method node under the class node, reading the name of the method node, and searching a target method node in the second metadata set, wherein the name of the target method node is the same as that of the method node;
if the target method node is not found, the change attribute of the member function corresponding to the method node is marked as the first attribute.
Optionally, after the target method node is searched in the second metadata set, the method further includes:
if the target method node is found, calculating a Levensstein distance according to the byte code sequence of the method node and the byte code sequence of the target method node;
if the Levensstein distance is larger than or equal to a preset threshold value, marking the change attribute of the member function corresponding to the method node as the first attribute;
and if the Levensstein distance is smaller than a preset threshold value, marking the change attribute of the member function corresponding to the method node as the second attribute.
All the above-mentioned optional technical solutions can be combined arbitrarily to form the optional embodiments of the present invention, and are not described herein again.
Fig. 3 is a flowchart of a test method based on code change analysis according to an embodiment of the present invention. The embodiment of the present invention may be applied to the test system shown in fig. 1, and each step in the embodiment of the present invention may be completed by cooperation of one or more units in the test system shown in fig. 1. Referring to fig. 3, the method includes:
301. compiling the java file to generate a plurality of class files, and storing the class files generated by current compilation to a specified directory.
In the embodiment of the invention, the java file is a source code file, and the class file is an executable file. The code compiling unit may compile the java file into a plurality of class files by executing a pre-configured compilation script. After each compilation, the class file storage unit may store the multiple class files generated by the current compilation to a specified directory of a class file library, and use the specified directory as a specified directory generated by the current compilation, where a name of the specified directory may be marked according to the current compilation time. The specified directories generated by each compiling are marked through compiling time, so that which class file generated by each compiling is stored in each specified directory can be conveniently confirmed, and corresponding operations including querying or processing the class files are conveniently performed on the class files.
302. According to a plurality of class files generated by current compilation and a plurality of class files generated by any one compilation before the current compilation, a first metadata set and a second metadata set of a tree structure are respectively generated, wherein the two metadata sets respectively comprise a plurality of class nodes and a plurality of method nodes under the class nodes, each class node corresponds to one class file, and each method node corresponds to one member function.
In the embodiment of the present invention, since the names of the specified directories stored in the class file generated by each compilation are marked according to the compilation time, the class file reading unit may determine the specified directory with the latest compilation time as the specified directory generated by the current compilation by comparing the compilation time indicated by each specified directory. Furthermore, the class file reading unit may search the target specified directory according to the compilation time indicated by the specified directory generated by the current compilation, and read and obtain a plurality of class files stored in the target specified directory, where the class files are a plurality of class files generated by any previous compilation before the current compilation, and the compilation time indicated by the name of the target specified directory is before the current compilation time.
In the embodiment of the present invention, in order to determine which member functions in a plurality of class files generated by current compilation have undergone code change, a difference analysis may be performed on the plurality of class files generated by current compilation and a plurality of class files generated by compilation at any time before current compilation. In order to facilitate the difference analysis, the first metadata set and the second metadata set of the tree structure may be generated according to a plurality of class files generated by current compilation and a plurality of class files generated by any compilation before the current compilation. Referring to fig. 4, fig. 4 is a schematic diagram of a metadata set with a tree structure according to an embodiment of the present invention, where an upper layer of the metadata set is a directory node, a lower layer is a plurality of class nodes, and a lower layer is a plurality of method nodes included in each class node.
Each class node in the first metadata set corresponds to a class file generated by previous compilation, and each class node in the second metadata set corresponds to a class file generated by previous compilation at any time. Because the metadata set is an organization form of a tree structure, each class node and a method node under each class node can be clearly distinguished, so that the test case screening unit can conveniently perform difference analysis on a plurality of class nodes generated by current compilation and a plurality of class nodes generated by any compiling before the current compilation by virtue of the first metadata set and the second metadata set, namely perform difference analysis on a plurality of class files generated by the current compilation and a plurality of class files generated by any compiling before the current compilation.
In this embodiment of the present invention, the generating process of the first metadata set and the second metadata set may include the following steps a to d:
a. and analyzing the plurality of class files generated by current compilation to obtain the names and summary information of the plurality of class files generated by current compilation and the names and byte code sequences of the plurality of member functions contained in each class file.
In the embodiment of the present invention, since the class files generated by each compiling are respectively stored in each specified directory, the class file reading unit may read the specified directory generated by the current compiling to obtain a plurality of class files generated by the current compiling, and then the class file analyzing unit analyzes the plurality of class files according to the specification of the Java virtual machine to obtain the related information of the plurality of class files, including the names and summary information of the plurality of class files, and the names and byte code sequences of the plurality of member functions included in each class file.
It should be noted that, the class file reading unit reads the specified directory generated by the current compilation, and may also obtain the name of the specified directory generated by the current compilation.
b. The method comprises the steps of forming a plurality of class nodes generated by current compilation based on names and summary information of a plurality of class files generated by current compilation, forming a plurality of method nodes generated by current compilation based on names and byte code sequences of a plurality of member functions contained in the class files for each class file generated by current compilation, taking the plurality of method nodes as child nodes of the class node corresponding to the class file, wherein each class node corresponds to one class file, and each method node corresponds to one member function.
In this embodiment of the present invention, after obtaining, through the analysis in step a, file information such as names and summary information of multiple currently compiled class files, the class file analyzing unit may form multiple class nodes in the first metadata set based on the file information. Of course, after the class file analyzing unit obtains the member function information such as the names and byte code sequences of the plurality of member functions included in each class file through the analysis in step a, a plurality of method nodes under each class node may be configured based on the member function information.
Each class node includes a name of the class node (i.e., a name of a class file corresponding to the class node), summary information (e.g., md5 information), and a plurality of member functions under the class node (i.e., member functions corresponding to a plurality of method nodes under the class node). Each method node contains the name of the method node (i.e., the name of the member function corresponding to the method node) and a bytecode sequence (e.g., a bytecode sequence code [ code _ length ] of a code attribute).
It should be noted that, the class file parsing unit may further configure a directory node in the first metadata set based on the name of the currently compiled specified directory obtained in step a, where the directory node includes the name of the directory node (i.e., the name of the currently compiled specified directory).
In order to improve the query efficiency, the metadata set with the tree structure in fig. 4 may be stored by HashMap, and the format is as follows:
Figure BDA0001260526590000101
through steps a to b, a plurality of class nodes generated by current compilation and a plurality of method nodes under each class node can be obtained, namely, a first metadata set is generated.
c. And analyzing the plurality of class files generated by any compiling before the current compiling to obtain the names and summary information of the plurality of class files generated by any compiling before the current compiling and the names and byte code sequences of the plurality of member functions contained in each class file.
d. The method comprises the steps of forming a plurality of class nodes generated by any compiling before the current compiling based on names and summary information of a plurality of class files generated by any compiling before the current compiling, forming a plurality of method nodes generated by any compiling before the current compiling based on names and byte code sequences of a plurality of member functions contained in each class file generated by any compiling before the current compiling, and taking the plurality of method nodes generated by any compiling before the current compiling as child nodes of the class nodes corresponding to the class files.
Similarly to steps a to b, through steps c to d, a plurality of class nodes generated by any one time of compilation before the current compilation and a plurality of method nodes under each class node can be obtained, that is, a second metadata set is generated.
It should be noted that, in the embodiment of the present invention, the first metadata set is generated first (i.e., step a to step b are executed), and then the second metadata set is generated (i.e., step c to step d are executed), which may actually be the second metadata set is generated first and then the first metadata set is generated, which is not limited in the embodiment of the present invention.
After the first metadata set and the second metadata set are generated through steps 301 to 302, the test case screening unit may perform difference analysis on the first metadata set and the second metadata set of the tree structure, that is, perform difference analysis on a plurality of class nodes in the first metadata set and a plurality of class nodes in the second metadata set, so as to obtain a member function of the code change. The process of the difference analysis will be described in the following steps 303 to 304.
303. For each class node in the first metadata set, reading the name of the class node, searching a target class node in the second metadata set, wherein the target class node is the same as the name of the class node, if the target class node cannot be searched, marking the change attributes of all member functions under the class node as first attributes, and the first attributes are used for indicating code change, and if the target class node is found, executing step 304.
In the embodiment of the present invention, since the first metadata set includes a plurality of class nodes, each class node has a plurality of method nodes, and each method node corresponds to one member function, in order to determine which member functions in a plurality of class files generated by current compilation have undergone code change, the plurality of class nodes may be sequentially analyzed.
For each class node in the first metadata set, taking class node 1 as an example, the test case screening unit may search for a target class node with the same name as the class node 1 in the second metadata set, and if the target class node cannot be searched in the second metadata set, it indicates that the class node 1 is a brand new class node generated by current compilation, that is, all member functions under the class node 1 have a code change. At this time, the test case screening unit may mark the changed attribute of all member functions under the class node as a first attribute (e.g., True). Taking the example that class node 1 includes member function a and member function B, the changed attribute of member function a and member function B may be marked as True. The member functions with changed codes are marked through the first attribute, and confirmation and acquisition of the member functions can be conveniently and subsequently acquired.
And if the target class node is found in the second metadata set, indicating that at least one member function under the class node 1 has no code change. At this time, the test case screening unit may further analyze class node 1 by performing step 304 to determine the code change.
304. If the target class node is found, comparing whether the summary information of the class node is the same as that of the target class node, if so, marking the change attributes of all member functions under the class node as second attributes which are used for indicating that no code change occurs, and if not, performing difference analysis on the method node under the class node and the method node under the target class node.
In the embodiment of the present invention, after determining that a target class node with the same name as class node 1 exists in the second metadata set, the test case screening unit may compare whether the digest information included in the class node 1 is the same as the digest information included in the target class node, and if the digest information included in the class node 1 is the same as the digest information included in the target class node, it indicates that the class node 1 is completely the same as the target class node, that is, it indicates that all member functions under the class node 1 have not undergone code change. At this time, the test case screening unit may mark the change attribute of all member functions under the class node as a second attribute (e.g., False). Taking class node 1 as an example, including member function a and member function B, the altered attributes of member function a and member function B may be marked as False.
If the summary information contained in the class node 1 is different from the summary information contained in the target class node, the code change of at least one member function under the class node 1 is shown. At this time, the test case screening unit may further analyze all the method nodes under the class node 1 to determine which member functions have undergone code change.
In this embodiment of the present invention, the process of performing difference analysis on the method node under the class node 1 and the method node under the target class node may include the following steps a to b:
a. for each method node under the class node 1, reading the name of the method node, and searching a target method node in the second metadata set, wherein the name of the target method node is the same as that of the method node; if the target method node cannot be found, marking the change attribute of the member function corresponding to the method node as the first attribute;
in the embodiment of the invention, because a plurality of method nodes are arranged under each class node, and each method node corresponds to one member function, in order to determine which member functions under the class node 1 have changed codes, the plurality of method nodes under the class node 1 can be sequentially analyzed.
For each method node under class node 1, taking method node 1 as an example, the test case screening unit may search for a target method node with the same name as that of method node 1 in the second metadata set, and if the target method node is not searched in the second metadata set, it indicates that a member function corresponding to the method node 1 has a code change. At this time, the test case screening unit may mark the change attribute of the member function corresponding to the method node 1 as the first attribute (e.g., True). Taking the member function a corresponding to the method node 1 as an example, the change attribute of the member function a may be marked as True.
If the target method node is found in the second metadata set, it indicates that the member function corresponding to the method node 1 may have a code change. In this case, the test case screening unit may further determine whether the member function corresponding to the method node 1 has a code change by executing step b.
b. If the target method node is found, calculating a Levenstein distance according to the byte code sequence of the method node and the byte code sequence of the target method node, if the Levenstein distance is larger than or equal to a preset threshold value, marking the change attribute of the member function corresponding to the method node as the first attribute, and if the Levenstein distance is smaller than the preset threshold value, marking the change attribute of the member function corresponding to the method node as the second attribute.
In the embodiment of the present invention, the levenstein distance can be used to measure the similarity between two byte code sequences. After determining that the second metadata set has the target method node with the same name as the method node 1, the test case screening unit may calculate the levenstein distance D between the bytecode of the method node 1 and the bytecode of the target method node according to a specified algorithm.
If D is greater than or equal to the preset threshold, it indicates that the similarity between the bytecode of the method node 1 and the bytecode of the target method node is low, and it can be considered that the membership function corresponding to the method node 1 has a code change. In this case, the test case screening unit may mark the change attribute of the member function corresponding to the method node 1 as the first attribute (e.g., True).
If D is smaller than the preset threshold, it indicates that the similarity between the bytecode of the method node 1 and the bytecode of the target method node is high, and it can be considered that the member function corresponding to the method node 1 has not been changed in code, in this case, the test case screening unit may mark the change attribute of the member function corresponding to the method node 1 as a second attribute (e.g., False).
In addition, step a to step b are processes of performing code change analysis on the method node 1 under the class node 1, for example. In the embodiment of the invention, the test case screening unit needs to perform code change analysis on each method node under class node 1, namely, execute steps a to b, and does not complete the process of performing code change analysis on the class node 1 until all the method nodes under the class node 1 traverse.
Steps 303 to 304 are processes of performing a difference analysis on the first metadata set and the second metadata set. In order to embody the specific analysis process of each class node, in the above steps, class node 1 in the first metadata set is taken as an example, and the analysis process of class node 1 is described, and the analysis processes of other nodes in the first metadata set are the same as the analysis process of class node 1. The test case screening unit needs to analyze each class node in the first metadata set, that is, execute steps 303 to 304 until all the class nodes in the first metadata set are traversed, and then execute the subsequent step 305. Since each class node comprises a plurality of member functions, all the member functions of the currently compiled and generated class nodes with changed codes can be obtained by traversing all the class nodes in the first metadata set.
It should be noted that the difference analysis process in steps 303 to 304 is only one example of the embodiment of the present invention, and of course, the process of performing difference analysis on the class node in the first metadata set and the class node in the second metadata set may also be implemented in other ways, which is not limited in the embodiment of the present invention.
305. And all member functions with the change attributes marked as first attributes in a plurality of class nodes generated by current compilation are acquired, a plurality of member functions with changed codes are acquired, and testing is performed on the basis of the test case sets generated by the test cases corresponding to the member functions one by one.
In the embodiment of the present invention, the test case screening unit performs difference analysis on the class node in the first metadata set and the class node in the second metadata set through the above steps 303 to 304, and marks the member function of which the code is changed with the first attribute. Therefore, the test case screening unit may acquire all the member functions marked with the first attribute as a plurality of member functions whose codes are changed.
In one possible implementation, the generating process of the test case set may include: for each member function in the plurality of member functions of which the code is changed, screening out a target test case from a test case library according to the member function and the specified calling relation, wherein the target test case is a test case for calling the member function to test; and acquiring the target test cases of the member functions as the test case set.
For example, the test case screening unit may store the specified call relationship, which is used to indicate a corresponding relationship between the member function and the test case that calls the member function for testing. The test case screening unit can determine a plurality of target test cases according to the specified calling relation and the member functions of which the codes are changed, then acquire the target test cases from the test case library, use the target test cases as the test case set, and then execute the test cases to complete the test.
It should be noted that, the implementation manner is described by taking an example that the specified call relation and the test case are separately stored, and actually, the specified call relation and the test case may also be correspondingly stored in the test case library. Correspondingly, for each member function of which the code is changed, the test case screening unit can directly acquire the test case corresponding to the member function from the test case library.
Referring to fig. 5, in order to more clearly embody the testing method provided by the embodiment of the present invention, the flowchart shown in fig. 5 is adopted to embody the whole process from step 301 to step 305, and the contents in fig. 5 are all explained in step 301 to step 305, which is not repeated herein.
According to the method provided by the embodiment of the invention, a plurality of member functions with changed codes are obtained by carrying out difference analysis on the class node in the first metadata set and the class node in the second metadata set, and then test cases corresponding to the plurality of member functions one by one are obtained for the plurality of member functions, and the test case set is generated according to the test cases for testing. The technical scheme can accurately reflect which member functions have code changes, the test cases selected according to the member functions have strong pertinence, the member function level pertinence test can be realized, and the test efficiency is improved.
Fig. 6 is a schematic structural diagram of a test apparatus based on code change analysis according to an embodiment of the present invention. Referring to fig. 6, the apparatus includes a generation module 601, an analysis module 602, and a test module 603:
a generating module 601, configured to generate a first metadata set and a second metadata set of a tree structure according to a plurality of class files generated by current compilation and a plurality of class files generated by any one compilation before the current compilation, where both metadata sets include a plurality of class nodes and a plurality of method nodes below the class nodes, each class node corresponds to one class file, and each method node corresponds to one member function;
an analysis module 602, configured to obtain a plurality of member functions of which codes are changed according to a difference analysis of the first metadata set and the second metadata set;
the testing module 603 is configured to perform testing based on a test case set generated based on the test cases corresponding to the plurality of member functions one to one.
Optionally, referring to fig. 7, the analysis module 602 includes:
the searching submodule is used for reading the name of any class node in the first metadata set and searching a target class node in the second metadata set, wherein the target class node and the name of the class node are the same;
and the marking submodule is used for marking the change attributes of all member functions under the class node as a first attribute if the target class node cannot be searched, wherein the first attribute is used for indicating that code change occurs.
Optionally, the search sub-module is further configured to, if the target class node is found and the digest information of the class node is the same as the digest information of the target class node, read a name of the method node for each method node under the class node, and find a target method node in the second metadata set, where the name of the target method node is the same as the name of the method node;
and the marking sub-module is further used for marking the change attribute of the method corresponding to the method node as the first attribute if the target method node is not found.
Optionally, referring to fig. 8, the analysis module 602 further includes a calculation sub-module:
the calculation submodule is used for calculating the Levenstein distance according to the byte code sequence of the method node and the byte code sequence of the target method node if the target method node is found;
if the Levensstein distance is larger than or equal to a preset threshold value, marking the change attribute of the method corresponding to the method node as the first attribute;
and if the Levensstein distance is smaller than a preset threshold value, marking the change attribute of the method corresponding to the method node as the second attribute.
In the embodiment of the invention, a plurality of member functions with changed codes are obtained by performing difference analysis on the class node in the first metadata set and the class node in the second metadata set, and then test cases corresponding to the plurality of member functions one by one are obtained for the plurality of member functions, and a test case set is generated according to the test cases for testing. The technical scheme can accurately reflect which member functions have code changes, the test cases selected according to the member functions have strong pertinence, the member function level pertinence test can be realized, and the test efficiency is improved.
It should be noted that: in the test device based on code change analysis provided in the above embodiment, only the division of the functional modules is illustrated in the description of the test based on code change analysis, and in practical applications, the functions may be distributed by different functional modules as needed, that is, the internal structure of the device may be divided into different functional modules to complete all or part of the functions described above. In addition, the code change analysis-based testing apparatus provided in the above embodiment and the code change analysis-based testing method embodiment belong to the same concept, and specific implementation processes thereof are described in the method embodiment and are not described herein again.
Fig. 9 is a block diagram of a test apparatus 900 based on code change analysis according to an embodiment of the present invention. Referring to fig. 9, apparatus 900 includes a processing component 9001 further including one or more processors and memory resources, represented by memory 9002, for storing instructions, e.g., applications, executable by processing component 9001. The application programs stored in the memory 9002 may include one or more modules each corresponding to a set of instructions. Further, the processing component 9001 is configured to execute instructions to perform the above-described test method based on code change analysis.
The device 900 may also include a power supply component 9003 configured to perform power management of the device 900, a wired or wireless network interface 9004 configured to connect the device 900 to a network, and an input-output (I/O) interface 9005. The device 900 may operate based on an operating system stored in the memory 9002,such as Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTMOr the like.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.

Claims (9)

1. A test method based on code change analysis, the method comprising:
compiling the java files to generate a plurality of class files, and storing the class files generated by current compilation into a specified directory, wherein the name of the specified directory is marked by current compilation time;
respectively generating a first metadata set and a second metadata set of a tree structure according to the plurality of class files and a plurality of class files generated by any compiling before the current compiling, wherein the first metadata set and the second metadata set respectively comprise a plurality of class nodes and a plurality of method nodes under the plurality of class nodes, each class node corresponds to one class file, and each method node corresponds to one member function;
obtaining a plurality of member functions of code change by the difference analysis of the first metadata set and the second metadata set; testing based on the test case set generated by the test cases corresponding to the plurality of member functions one by one;
for the first metadata set and the second metadata set, the generation process of any metadata set comprises the following steps:
analyzing a plurality of class files generated by compiling to obtain names and summary information of the class files and names and byte code sequences of a plurality of member functions contained in each class file; and forming a plurality of class nodes based on the names and the summary information of the class files, forming a plurality of method nodes based on the names and the byte code sequences of a plurality of member functions contained in the class files for each class file, and taking the plurality of method nodes as the child nodes of the class nodes corresponding to the class files.
2. The method according to claim 1, wherein the differential analysis with the first metadata set and the second metadata set specifically includes:
for any class node in the first metadata set, reading the name of the class node, and searching a target class node in the second metadata set, wherein the name of the target class node is the same as that of the class node;
and if the target class node cannot be searched, marking the change attributes of all member functions under the class node as first attributes, wherein the first attributes are used for indicating that code change occurs.
3. The method of claim 2, wherein after searching for a target class node in the second metadata set, the method further comprises:
if the target class node is found, comparing whether the summary information of the class node is the same as the summary information of the target class node;
if the attribute is the same as the attribute, marking the changed attribute of all member functions under the class node as a second attribute, wherein the second attribute is used for indicating that no code change occurs;
and if the class node is different from the target class node, performing difference analysis on the method node under the class node and the method node under the target class node.
4. The method of claim 3, wherein the performing a difference analysis on the method node under the class node and the method node under the target class node comprises:
for each method node under the class node, reading the name of the method node, and searching a target method node in the second metadata set, wherein the name of the target method node is the same as that of the method node;
and if the target method node cannot be found, marking the change attribute of the member function corresponding to the method node as the first attribute.
5. The method of claim 4, wherein after searching for a target method node in the second metadata set, the method further comprises:
if the target method node is found, calculating a Levensstein distance according to the byte code sequence of the method node and the byte code sequence of the target method node;
if the Levensstein distance is larger than or equal to a preset threshold value, marking the change attribute of the member function corresponding to the method node as the first attribute;
and if the Levensstein distance is smaller than a preset threshold value, marking the change attribute of the member function corresponding to the method node as the second attribute.
6. A test apparatus based on code change analysis, the apparatus comprising:
the system comprises a generation module, a first storage module, a second storage module and a third storage module, wherein the generation module is used for respectively generating a first metadata set and a second metadata set of a tree structure according to a plurality of class files generated by current compilation and a plurality of class files generated by any one time of compilation before the current compilation, the first metadata set and the second metadata set both comprise a plurality of class nodes and a plurality of method nodes under the class nodes, each class node corresponds to one class file, and each method node corresponds to one member function;
the analysis module is used for obtaining a plurality of member functions of which the codes are changed by the difference analysis of the first metadata set and the second metadata set;
the testing module is used for testing based on a test case set generated by the test cases which are in one-to-one correspondence with the plurality of member functions;
the generating module is used for analyzing the plurality of class files generated by compiling to obtain the names and summary information of the plurality of class files and the names and byte code sequences of a plurality of member functions contained in each class file; forming a plurality of class nodes based on the names and summary information of the class files, forming a plurality of method nodes based on the names and byte code sequences of a plurality of member functions contained in the class files for each class file, and taking the plurality of method nodes as child nodes of the class nodes corresponding to the class files;
the device also comprises a module for compiling java files, generating the class files and storing the class files generated by current compilation into a specified directory, wherein the name of the specified directory is marked by the current compilation time.
7. The apparatus of claim 6, wherein the analysis module comprises:
the searching sub-module is used for reading the name of any class node in the first metadata set and searching a target class node in the second metadata set, wherein the name of the target class node is the same as that of the class node;
and the marking submodule is used for marking the change attributes of all member functions under the class node as a first attribute if the target class node cannot be searched, wherein the first attribute is used for indicating that code change occurs.
8. The apparatus according to claim 7, wherein the search sub-module is further configured to, if the target class node is found and the summary information of the class node is the same as the summary information of the target class node, read a name of the method node for each method node under the class node, and find a target method node in the second metadata set, where the name of the target method node is the same as the name of the method node;
the marking sub-module is further configured to mark a change attribute of the member function corresponding to the method node as the first attribute if the target method node is not found.
9. The apparatus of claim 8, wherein the analysis module further comprises a computation submodule:
the calculation submodule is used for calculating the Levenstein distance according to the byte code sequence of the method node and the byte code sequence of the target method node if the target method node is found;
the marking sub-module is further configured to mark a change attribute of the member function corresponding to the method node as the first attribute if the levenstein distance is greater than or equal to a preset threshold value;
the marking sub-module is further configured to mark a change attribute of the member function corresponding to the method node as a second attribute if the levenstein distance is smaller than a preset threshold value.
CN201710211420.8A 2017-03-31 2017-03-31 Test method and device based on code change analysis Active CN107015909B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710211420.8A CN107015909B (en) 2017-03-31 2017-03-31 Test method and device based on code change analysis

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710211420.8A CN107015909B (en) 2017-03-31 2017-03-31 Test method and device based on code change analysis

Publications (2)

Publication Number Publication Date
CN107015909A CN107015909A (en) 2017-08-04
CN107015909B true CN107015909B (en) 2020-03-27

Family

ID=59444878

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710211420.8A Active CN107015909B (en) 2017-03-31 2017-03-31 Test method and device based on code change analysis

Country Status (1)

Country Link
CN (1) CN107015909B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117215965B (en) * 2023-11-09 2024-02-27 恒生电子股份有限公司 Test case identification-based test method and device, electronic equipment and medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0844590A (en) * 1994-05-16 1996-02-16 At & T Corp Apparatus and method for selection test of software system
CN103617122A (en) * 2013-12-12 2014-03-05 用友软件股份有限公司 Comparison method for source codes
CN103678097A (en) * 2012-09-05 2014-03-26 百度在线网络技术(北京)有限公司 Method and device for selecting regression test case
CN105760288A (en) * 2014-12-15 2016-07-13 阿里巴巴集团控股有限公司 Method and device testing rewritten application program

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0844590A (en) * 1994-05-16 1996-02-16 At & T Corp Apparatus and method for selection test of software system
CN103678097A (en) * 2012-09-05 2014-03-26 百度在线网络技术(北京)有限公司 Method and device for selecting regression test case
CN103617122A (en) * 2013-12-12 2014-03-05 用友软件股份有限公司 Comparison method for source codes
CN105760288A (en) * 2014-12-15 2016-07-13 阿里巴巴集团控股有限公司 Method and device testing rewritten application program

Also Published As

Publication number Publication date
CN107015909A (en) 2017-08-04

Similar Documents

Publication Publication Date Title
CN108334515B (en) Method, device and system for processing stack address in crash file
CN109032631B (en) Application program patch package obtaining method and device, computer equipment and storage medium
CN110737437A (en) compiling method and device based on code integration
Espinosa et al. Automatic performance evaluation of parallel programs
CN111124872A (en) Branch detection method and device based on difference code analysis and storage medium
CN112925757A (en) Method, equipment and storage medium for tracking operation log of intelligent equipment
CN111831574A (en) Regression test planning method, device, computer system and medium
CN113495728A (en) Dependency relationship determination method, dependency relationship determination device, electronic equipment and medium
CN108897678B (en) Static code detection method, static code detection system and storage device
US20160147547A1 (en) Metadata-based class loading using a content repository
CN107015909B (en) Test method and device based on code change analysis
CN113495723B (en) Method, device and storage medium for calling functional component
CN113157296B (en) Method and device for updating compiled file, server and storage medium
CN115757174A (en) Database difference detection method and device
US20150347402A1 (en) System and method for enabling a client system to generate file system operations on a file system data set using a virtual namespace
CN112052035B (en) Version group package method and device based on bank back line system
CN115408427A (en) Method, device and equipment for data search
CN113656318A (en) Software version testing method and device and computer equipment
CN110737429A (en) modular compiling method and device utilizing Makefile self-dependent relationship
CN113778450A (en) Processing method, device and equipment for dependency conflict and storage medium
CN112749189A (en) Data query method and device
CN110688430A (en) Method and device for obtaining data bypass and electronic equipment
CN115658551B (en) Code testing method, storage medium, electronic device and apparatus
CN113568662B (en) Code change influence range analysis method and system based on calling relation
CN115016795A (en) Code similarity detection method and device, processor and electronic equipment

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
CP01 Change in the name or title of a patent holder
CP01 Change in the name or title of a patent holder

Address after: 266555 Qingdao economic and Technological Development Zone, Shandong, Hong Kong Road, No. 218

Patentee after: Hisense Video Technology Co., Ltd

Address before: 266555 Qingdao economic and Technological Development Zone, Shandong, Hong Kong Road, No. 218

Patentee before: HISENSE ELECTRIC Co.,Ltd.