CN107015909A - Method of testing and device based on code analysis on altered project - Google Patents
Method of testing and device based on code analysis on altered project Download PDFInfo
- Publication number
- CN107015909A CN107015909A CN201710211420.8A CN201710211420A CN107015909A CN 107015909 A CN107015909 A CN 107015909A CN 201710211420 A CN201710211420 A CN 201710211420A CN 107015909 A CN107015909 A CN 107015909A
- Authority
- CN
- China
- Prior art keywords
- nodes
- class
- target
- attribute
- metadata set
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000010998 test method Methods 0.000 title claims abstract description 14
- 238000000034 method Methods 0.000 claims abstract description 212
- 230000006870 function Effects 0.000 claims abstract description 144
- 238000012360 testing method Methods 0.000 claims abstract description 117
- 230000008859 change Effects 0.000 claims description 64
- 230000008569 process Effects 0.000 claims description 18
- 239000012141 concentrate Substances 0.000 claims description 2
- 238000012216 screening Methods 0.000 description 23
- 238000001514 detection method Methods 0.000 description 6
- 238000012545 processing Methods 0.000 description 4
- 238000010586 diagram Methods 0.000 description 3
- 238000012544 monitoring process Methods 0.000 description 2
- 241000208340 Araliaceae Species 0.000 description 1
- 235000005035 Panax pseudoginseng ssp. pseudoginseng Nutrition 0.000 description 1
- 235000003140 Panax quinquefolius Nutrition 0.000 description 1
- 238000012356 Product development Methods 0.000 description 1
- 230000009471 action Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000012790 confirmation Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 235000008434 ginseng Nutrition 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000005303 weighing Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
- Debugging And Monitoring (AREA)
Abstract
The invention discloses a kind of method of testing based on code analysis on altered project and device, belong to computer realm.Method includes:According to multiple class files of any compiling generation before multiple class class files of current compiling generation and current compiling, the first metadata set and the second metadata set of tree are generated respectively;With the variance analysis of the first metadata set and the second metadata set, multiple member functions that code is changed are obtained;Tested based on the test use cases with the one-to-one Test cases technology of the multiple member function.The present invention is with strong points according to the test case that these member functions are chosen by can accurately reflect which member function there occurs that code is changed, it is possible to achieve the specific aim test of member function rank, improves testing efficiency.
Description
Technical field
The present invention relates to computer realm, more particularly to a kind of method of testing and device based on code analysis on altered project.
Background technology
With being growing more intense for market competition, to the rate request more and more higher of product development.Product on stream,
Generally require by various tests.For the test of product, developer can typically develop many test cases, with
Cover scene as much as possible.Product on stream, may be related to the change of source code file, now need to this
Change is analyzed, and is then based on analysis result selection test case and is targetedly tested.
At present, method of testing can include:Automatic monitoring source code file, if source code file is changed, such as source
The timestamp of code file is changed, then it is assumed that the corresponding class of the source code file changes, and then enters for such
Row test, i.e., filter out such corresponding all test case, and perform these test cases to complete from test case library
Test.Wherein, class refers to the file that generation is compiled by the source code file.
During the present invention is realized, inventor has found that prior art at least has problems with:
Above-mentioned technology enters line code analysis on altered project by way of monitoring source code file, the granularity limitation that can be monitored
In the rank of class, class can only be analyzed and changed, it is impossible to accurately reflect which of such code is become
More, the test case specific aim based on class selection is poor, causes testing efficiency low.
The content of the invention
In order to solve problem of the prior art, the embodiments of the invention provide a kind of test side based on code analysis on altered project
Method and device.The technical scheme is as follows:
First aspect includes there is provided a kind of method of testing based on code analysis on altered project, methods described:
Any compiling generation is multiple before compiling according to multiple class class files of currently compiling generation and currently
Class files, branch generates the first metadata set and the second metadata set of tree, and two metadata sets include many
Multiple method nodes under individual class nodes, and the multiple class nodes, one class of each class nodes correspondence
File, one member function of each method nodes correspondence;
With the variance analysis of first metadata set and second metadata set, it is multiple that acquisition code is changed
Member function;
Tested based on the test use cases with the one-to-one Test cases technology of the multiple member function.
In the first implementation of first aspect, for first metadata set and second metadata set
In, the generating process of any piece of metadata collection includes:
Parsing compiling generation multiple class files, obtain the multiple class files title and summary info, with
And the title of multiple member functions that includes of each class files and byte code sequence;
Title and summary info based on the multiple class files, constitute multiple class nodes, for each class
File, the title and byte code sequence of the multiple member functions included based on the class files constitute multiple method sections
Point, and using the multiple method nodes as the corresponding class nodes of the class files child node.
It is described with first metadata set and second metadata set in second of implementation of first aspect
Variance analysis, specifically include:
For any class nodes in first metadata set, the title of the class nodes is read, described
Target class nodes are searched in second metadata set, the target class nodes are identical with the title of the class nodes;
If searched less than the target class nodes, the change of all member functions under the class nodes is belonged to
Property be labeled as the first attribute, first attribute be used for indicate occur code change.
It is described that target class sections are searched in second metadata set in the third implementation of first aspect
After point, methods described also includes:
If finding the target class nodes, the summary info and the target of the class nodes
Whether the summary info of class nodes is identical;
If identical, the change attribute of all member functions under the class nodes is labeled as the second attribute, described the
Two attributes are used to indicate that code change does not occur;
If it is different, then to the method under the method nodes under the class nodes and the target class nodes
Node carries out variance analysis.
In the 4th kind of implementation of first aspect, method nodes under the class nodes and described
Method nodes under target class nodes, which carry out variance analysis, to be included:
For each method nodes under the class nodes, the title of the method nodes is read, described the
Binary data, which is concentrated, searches target method nodes, and the target method nodes are identical with the title of the method nodes;
If searched less than the target method nodes, by the change of the corresponding member function of the method nodes
Attribute is labeled as first attribute.
It is described that target method sections are searched in second metadata set in the 5th kind of implementation of first aspect
After point, methods described also includes:
If finding the target method nodes, according to the byte code sequence and the mesh of the method nodes
The byte code sequence of method nodes is marked, Levenstein distance is calculated;
If Levenstein distance is more than or equal to predetermined threshold value, by the method nodes it is corresponding into
The change attribute of member's function is labeled as first attribute;
If the Levenstein distance is less than predetermined threshold value, by the corresponding member function of the method nodes
Change attribute and be labeled as second attribute.
Second aspect includes there is provided a kind of test device based on code analysis on altered project, described device:
Generation module, is compiled for any time before multiple class class files according to current compiling generation and current compiling
Multiple class files of generation are translated, the first metadata set and the second metadata set of tree, this two first numbers are generated respectively
Include multiple method nodes under multiple class nodes, and the multiple class nodes, each method nodes according to collection
One member function of correspondence;
Analysis module, for the variance analysis of first metadata set and second metadata set, obtaining code
The multiple member functions changed;
Test module, for based on the test use cases with the one-to-one Test cases technology of the multiple member function
Tested.
In the first implementation of second aspect, the analysis module includes:
Submodule is searched, for for any class nodes in first metadata set, reading the class sections
The title of point, searches target class nodes in second metadata set, and the target class nodes are saved with the class
The title of point is identical;
Submodule is marked, if for searching less than the target class nodes, will own under the class nodes
The change attribute of member function is labeled as the first attribute, and first attribute is used to indicate occur code change.
In second of implementation of second aspect, the lookup submodule, if being additionally operable to find the target
Class nodes, and the summary info of the class nodes is identical with the summary info of the target class nodes, then for institute
Each method nodes under class nodes are stated, the title of the method nodes is read, is looked into second metadata set
Target method nodes are looked for, the target method nodes are identical with the title of the method nodes;
Submodule is marked, if being additionally operable to search less than the target method nodes, by the method nodes pair
The change attribute for the member function answered is labeled as first attribute.
In the third implementation of second aspect, the analysis module also includes calculating sub module:
The calculating sub module, if for finding the target method nodes, according to the method nodes
Byte code sequence and the target method nodes byte code sequence, calculate Levenstein distance;
The mark submodule, will if being additionally operable to the Levenstein distance is more than or equal to predetermined threshold value
The change attribute of the corresponding member function of the method nodes is labeled as first attribute;
The mark submodule, will be described if being additionally operable to the Levenstein distance is less than predetermined threshold value
The change attribute of the corresponding member function of method nodes is labeled as second attribute.
The beneficial effect that technical scheme provided in an embodiment of the present invention is brought is:
By carrying out difference point to the class nodes in the class nodes and the second metadata set in the first metadata set
Analysis, to obtain multiple member functions that code is changed, and then for the plurality of member function, is obtained and the plurality of member's letter
The one-to-one test case of number, and tested according to these Test cases technology test use cases.Above-mentioned technical proposal can
Accurately to reflect which member function there occurs the test case specific aim that code is changed, and is chosen according to these member functions
By force, it is possible to achieve the specific aim test of member function rank, testing efficiency is improved.
Brief description of the drawings
Technical scheme in order to illustrate the embodiments of the present invention more clearly, makes required in being described below to embodiment
Accompanying drawing is briefly described, it should be apparent that, drawings in the following description are only some embodiments of the present invention, for
For those of ordinary skill in the art, on the premise of not paying creative work, other can also be obtained according to these accompanying drawings
Accompanying drawing.
Fig. 1 is a kind of structural representation of test system provided in an embodiment of the present invention;
Fig. 2 is a kind of flow chart of method of testing based on code analysis on altered project provided in an embodiment of the present invention;
Fig. 3 is a kind of flow chart of method of testing based on code analysis on altered project provided in an embodiment of the present invention;
Fig. 4 is a kind of schematic diagram of the metadata set of tree provided in an embodiment of the present invention;
Fig. 5 is a kind of flow chart of method of testing based on code analysis on altered project provided in an embodiment of the present invention;
Fig. 6 is a kind of structural representation of test device based on code analysis on altered project provided in an embodiment of the present invention;
Fig. 7 is a kind of structural representation of analysis module 602 provided in an embodiment of the present invention;
Fig. 8 is the structural representation of another analysis module 602 provided in an embodiment of the present invention;
Fig. 9 is the block diagram that a kind of test based on code analysis on altered project provided in an embodiment of the present invention is put.
Embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing to embodiment party of the present invention
Formula is described in further detail.
Fig. 1 is a kind of structural representation of test system provided in an embodiment of the present invention.The test system is compiled including code
Translate unit 101, class file storage units 102, class libraries 103, class document reading units 104, class files
Resolution unit 105, test case screening unit 106 and test case library 107.
Wherein, the code compilation unit 101 is responsible for compiling work every time, including the compiling generation of java files is corresponding
Class files;The class files that class file storage units 102 are responsible for generating code compilation unit 101 are stored to class
The assigned catalogue of library 103;Class document reading units 104 are responsible for reading the class texts of compiling generation from assigned catalogue
Part, is handled for class document analysis unit 104;Class document analysis unit 105 is responsible for the rule according to Java Virtual Machine
Model, parses class files, obtains the relevant information of the class files, and based on the relevant information, generate the member of tree
Data set;Test case screening unit 106 is responsible for carrying out variance analysis to tree metadata set, obtains code and changes
Member function, then according to these member functions, filtered out from test case library these member functions it is corresponding test use
Example;Test case library 107 is used to provide multiple test cases.
In following embodiment of the present invention, each step is in practice likely to be some or multiple lists by the test system
Member cooperation complete, concrete condition will the step of subsequent embodiment in illustrate.
Fig. 2 is a kind of flow chart of method of testing based on code analysis on altered project provided in an embodiment of the present invention.Referring to figure
2, this method includes:
What any compiling was generated before the multiple class class files the 201st, generated according to current compiling and current compiling is more
Individual class files, generate the first metadata set and the second metadata set of tree respectively, and two metadata sets include
Multiple method nodes under multiple class nodes, and the multiple class nodes, each class nodes correspondence one
Class files, one member function of each method nodes correspondence.
202nd, with the variance analysis of first metadata set and second metadata set, it is multiple that acquisition code is changed
Member function.
203rd, tested based on the test use cases with the one-to-one Test cases technology of the plurality of member function.
Method provided in an embodiment of the present invention, by the class nodes and the second metadata set in the first metadata set
In class nodes carry out variance analysis, to obtain multiple member functions that code is changed, and then be directed to the plurality of member
Function, is obtained and the one-to-one test case of the plurality of member function, and according to these Test cases technology test use cases
Tested.Above-mentioned technical proposal can accurately reflect which member function there occurs that code is changed, according to these members
The test case that function is chosen is with strong points, it is possible to achieve the specific aim test of member function rank, improves testing efficiency.
Alternatively, in first metadata set and second metadata set, the generating process collection of any piece of metadata collection
Including:
Parsing compiling generation multiple class files, obtain the plurality of class files title and summary info and
The title and byte code sequence for multiple member functions that each class files are included;
Title and summary info based on the plurality of class files, constitute multiple class nodes, for each class texts
Part, the title and byte code sequence of the multiple member functions included based on the class files constitute the multiple of current compiling generation
Method nodes, and using the plurality of method nodes as the corresponding class nodes of the class files child node;
Alternatively, it should be specifically included with the variance analysis of first metadata set and second metadata set:
For any class nodes in first metadata set, the title of the class nodes is read, at this second yuan
Target class nodes are searched in data set, target class nodes are identical with the title of the class nodes;
If searched less than target class nodes, by the change attribute mark of all member functions under the class nodes
The first attribute is designated as, first attribute is used to indicate occur code change.
Alternatively, it should be searched in second metadata set after target class nodes, this method also includes:
If finding target class nodes, the summary info and target class for comparing the class nodes are saved
Whether the summary info of point is identical;
If identical, lower methodical change attribute of the class nodes is labeled as the second attribute, second attribute is used
Code change does not occur in instruction;
If it is different, then to the method nodes under the method nodes under the class nodes and target class nodes
Carry out variance analysis.
Alternatively, the method nodes under the method nodes under the class nodes and target class nodes are carried out
Variance analysis includes:
For each method nodes under the class nodes, the title of the method nodes is read, in the binary number
Target method nodes are searched according to concentrating, target method nodes are identical with the title of the method nodes;
If searched less than target method nodes, by the change attribute of the corresponding member function of method nodes
Labeled as first attribute.
Alternatively, it should be searched in second metadata set after target method nodes, this method also includes:
If target method nodes are found, according to the byte code sequence of the method nodes and the target
The byte code sequence of method nodes, calculates Levenstein distance;
If Levenstein distance is more than or equal to predetermined threshold value, by the corresponding member's letter of the method nodes
Several change attributes is labeled as first attribute;
If Levenstein distance is less than predetermined threshold value, by the change of the corresponding member function of method nodes
Attribute is labeled as second attribute.
Above-mentioned all optional technical schemes, can form the alternative embodiment of the present invention, herein no longer using any combination
Repeat one by one.
Fig. 3 is a kind of flow chart of method of testing based on code analysis on altered project provided in an embodiment of the present invention.The present invention
Embodiment can apply in the test system shown in Fig. 1, the survey that each step in the embodiment of the present invention can be as shown in Figure 1
Some in test system or the cooperation completion of multiple units.Referring to Fig. 3, this method includes:
301st, java files are compiled, generate multiple class (class) files, and the multiple of generation are compiled by current
Class files are stored to assigned catalogue.
In the embodiment of the present invention, java files are source code file, and class files are executable file.Code compilation list
The compiling of java files can be generated multiple class files by member by performing the compilation script being pre-configured with.Compiling is completed every time
Afterwards, class file storage units can store the plurality of class files of current compiling generation to the finger of class libraries
Determine catalogue, and using the assigned catalogue as the assigned catalogue of current compiling generation, the title of the assigned catalogue can be according to current
Compilation time is marked.The assigned catalogue of compiling generation every time is marked by compilation time, can be in order to confirming
What is stored in each assigned catalogue is the class files of which time compiling generation, so that convenient carry out phase to these class files
It should operate, including inquiry or processing class files.
What any compiling was generated before the multiple class files the 302nd, generated according to current compiling and current compiling is multiple
Class files, generate the first metadata set and the second metadata set of tree respectively, and two metadata sets include many
Multiple method nodes under individual class nodes, and the multiple class nodes, one class of each class nodes correspondence
File, one member function of each method nodes correspondence.
In the embodiment of the present invention, by the title for compiling the assigned catalogue that the class files of generation are stored every time is pressed
Marked according to compilation time, therefore, class document reading units can be by the volume indicated by relatively more each assigned catalogue
The time is translated, the assigned catalogue of compilation time the latest is defined as to the assigned catalogue of current compiling generation.And then class files are read
Unit can search target assigned catalogue, and read according to the compilation time indicated by the assigned catalogue of current compiling generation
The multiple class files stored into the target assigned catalogue, any volume before the plurality of class files are current compiling
Translate multiple class files of generation, the compilation time that the name referring of the target assigned catalogue shows is before current compilation time.
In the embodiment of the present invention, which member function occurs in multiple class files in order to determine current compiling generation
Code change, can to before the multiple class files of current compiling generation and current compiling any compiling generation it is many
Individual class files carry out variance analysis.And for the ease of the variance analysis, can be respectively according to the multiple of current compiling generation
Multiple class files of any compiling generation, generate the first metadata of tree before class files and current compiling
Collection and the second metadata set.Referring to Fig. 4, Fig. 4 is a kind of signal of the metadata set of tree provided in an embodiment of the present invention
Figure, the most last layer of the metadata set is directory node, and next layer is multiple class nodes, then next layer is each class sections
Multiple method nodes that point includes.
Wherein, a class file of the current compiling generation of each class nodes correspondence in the first metadata set, the
A class file of any compiling generation before the current compiling of each class nodes correspondence that binary data is concentrated.Due to
Metadata set is the organizational form of tree, can be clearly distinguished under each class nodes and each class nodes
Method nodes, thus by first metadata set and the second metadata set, test case screening unit can be facilitated to working as
Multiple class nodes of any compiling generation carry out difference before multiple class nodes of preceding compiling generation and current compiling
Multiple class that any time compiles generation before analysis, namely the multiple class files generated to current compiling and current compiling
File carries out variance analysis.
In the embodiment of the present invention, the generating process of first metadata set and the second metadata set may comprise steps of
A to d:
A, multiple class files of the current compiling generation of parsing, obtain the name of multiple class files of current compiling generation
The title and byte code sequence for multiple member functions that title and summary info and each class files are included.
In the embodiment of the present invention, because the class files of compiling generation every time are respectively stored in each assigned catalogue, because
This, class document reading units can read the assigned catalogue of current compiling generation, obtain the multiple of current compiling generation
Class files, then by specification of the class document analysis unit according to Java Virtual Machine, parse the plurality of class files, obtain
The relevant information of the plurality of class files, includes the title and summary info and each class texts of the plurality of class files
The title and byte code sequence for multiple member functions that part is included.
It should be noted that class document reading units read the assigned catalogue of current compiling generation, it can also be worked as
The title of the assigned catalogue of preceding compiling generation.
B, the title of the multiple class files generated based on current compiling and summary info, constitute current compiling generation
Multiple class nodes, for each class files of current compiling generation, the multiple member's letters included based on the class files
Several titles and byte code sequence, constitute multiple method nodes of current compiling generation, and the plurality of method nodes are made
For the child node of the corresponding class nodes of the class files, each class nodes correspond to a class file, each
Method nodes one member function of correspondence.
In the embodiment of the present invention, class document analysis unit is parsed by above-mentioned steps a obtains many of current compiling generation
After the fileinfos such as the title and summary info of individual class files, this document information can be based on, is constituted in the first metadata set
Multiple class nodes.Certainly, class document analysis unit is obtained each class files and included by above-mentioned steps a parsings
Multiple member functions title and the member function information such as byte code sequence after, the member function information can be based on, constituted
Multiple method nodes under each class nodes.
Wherein, title (the i.e. class node corresponding class file of each class nodes comprising the class nodes
Title), multiple member functions under summary info (such as md5 information) and the class nodes are (i.e. under the class nodes
The corresponding member function of multiple method nodes).Each method nodes include title (i.e. method of the method nodes
The title of the corresponding member function of node) and the byte code sequence (byte code sequence code [code_ of such as code attributes
length])。
It should be noted that class document analysis units are also based on specifying for the current compiling generation that step a is obtained
The title of catalogue, constitutes the directory node in the first metadata set, and the title that the directory node includes directory node is (i.e. current to compile
Translate the title of the assigned catalogue of generation).
In order to which the metadata set for improving tree in search efficiency, above-mentioned Fig. 4 can be stored using HashMap,
Form is as follows:
The multiple class nodes and each class nodes of current compiling generation can be obtained by step a to step b
Under multiple method nodes, that is, generate the first metadata set.
Multiple class files of any compiling generation, any before currently being compiled before c, the current compiling of parsing
Multiple member functions that the title and summary info of multiple class files of secondary compiling generation and each class files are included
Title and byte code sequence.
D, title and summary info based on multiple class files of any compiling generation before current compiling, are constituted
Multiple class nodes that any time compiles generation before current compiling, the every of generation is compiled for any time before current compiling
Individual class files, the title and byte code sequence of the multiple member functions included based on the class files constitute current compiling
Multiple method nodes that before any compiling is generated, and multiple method that any compiling before current compiling is generated
Node as the corresponding class nodes of the class files child node.
With step a to step b similarly, any compiling generation before can currently being compiled to step d by step c
Multiple class nodes and each class nodes under multiple method nodes, that is, generate the second metadata set.
It should be noted that the embodiment of the present invention be with first generate the first metadata set (i.e. perform step a to step b),
The second metadata set is regenerated (i.e. to illustrate exemplified by execution step c to step d), in fact, second yuan can also first be generated
Data set, regenerates the first metadata set, and the embodiment of the present invention is not limited this.
Generated by step 301 to step 302 after the first metadata set and the second metadata set, test case screening unit
Variance analysis can be carried out to the first metadata set of tree and the second metadata set, i.e., to many in the first metadata set
Multiple class nodes in individual class nodes and the second metadata set carry out variance analysis, with obtain that code changes into
Member's function.The process of the variance analysis will be illustrated in subsequent step 303 into step 304.
303rd, for each class nodes in the first metadata set, the title of the class nodes is read, at second yuan
Target class nodes are searched in data set, target class nodes are identical with the title of the class nodes, if searched less than mesh
Class nodes are marked, then the change attribute of all member functions under the class nodes are labeled as the first attribute, first attribute
For indicating occur code change, if finding target class nodes, step 304 is performed.
In the embodiment of the present invention, because the first metadata set includes having under multiple class nodes, each class nodes
Multiple method nodes, and each method nodes one member function of correspondence, in order to determine the multiple of current compiling generation
Which member function there occurs that code is changed in class files, and the plurality of class nodes can be analyzed successively.
For each class nodes in the first metadata set, by taking class nodes 1 as an example, test case screening unit can
To be searched and the class nodes 1 target class nodes of the same name in the second metadata set, if in the second metadata set
Search less than target class nodes, then it is the brand-new class nodes of current compiling generation to illustrate the class nodes 1, i.e., should
All member functions under class nodes 1 there occurs that code is changed.Now, test case screening unit can be by the class
The change attribute of all member functions is labeled as the first attribute (such as True) under node.Member function A is included with class nodes 1
Exemplified by member function B, the change attribute that can mark member function A and member function B is True.By the first attribute to generation
The member function that changes of code is marked, can be in order to subsequently obtaining the confirmation and acquisition to these member functions.
And if finding target class nodes in the second metadata set, then illustrate under the class nodes 1 at least
Code change does not occur for one member function.Now, test case screening unit can be further right by performing step 304
The class nodes 1 are analyzed, to determine the situation of code change.
If the 304, finding target class nodes, compare the summary info and target class sections of the class nodes
Whether the summary info of point is identical, if identical, and the change attribute of all member functions under the class nodes is labeled as into second
Attribute, second attribute is used to indicate that code change does not occur, if it is different, then to the method nodes under the class nodes
Variance analysis is carried out with the method nodes under target class nodes.
In the embodiment of the present invention, test case screening unit in the second metadata set it is determined that exist same with class nodes 1
After the target class nodes of name, can compare that the summary info and target class nodes that the class nodes 1 include include plucks
Want information whether identical, if identical, illustrate that the class nodes 1 are identical with target class nodes, namely explanation should
Code change does not occur for all member functions under class nodes 1.Now, test case screening unit can be by the class
The change attribute of all member functions is labeled as the second attribute (such as False) under node.Member function A is included with class nodes 1
Exemplified by member function B, the change attribute that can mark member function A and member function B is False.
And if the summary info that includes of the class nodes 1 is different with the summary info that target class nodes are included, then
Illustrate that 1 time at least one member function of the class nodes there occurs that code is changed.Now, test case screening unit can be with
Further all method nodes under the class nodes 1 are analyzed, are which member function there occurs code to determine
Change.
In the embodiment of the present invention, under the method nodes under the class nodes 1 and target class nodes
The process that method nodes carry out variance analysis may comprise steps of a to b:
A, for each method nodes under the class nodes 1, read the title of the method nodes, this second
Target method nodes are searched in metadata set, target method nodes are identical with the title of the method nodes;If looked into
Target method nodes are can not find, then by the change attribute of the corresponding member function of method nodes labeled as first category
Property;
In the embodiment of the present invention, due to there is multiple method nodes under each class nodes, and each method nodes pair
A member function is answered, can be to the class in order to determine that 1 time which member function of the class nodes there occurs that code is changed
Multiple method nodes under node 1 are analyzed successively.
For each method nodes under the class nodes 1, by taking method nodes 1 as an example, test case screening unit
It can be searched in the second metadata set and the method nodes 1 target method nodes of the same name, if in the second metadata
Concentrate and search less than target method nodes, then illustrate that the corresponding member function of method nodes 1 there occurs that code is changed.
Now, test case screening unit can be by the change attribute of the corresponding member function of method nodes 1 labeled as the first category
Property (such as True).By taking the corresponding member function A of the method nodes 1 as an example, the change attribute that can mark member function A is
True。
And if finding target method nodes in the second metadata set, then illustrate that the method nodes 1 are corresponding
Member function has been likely to occur code change.Now, test case screening unit can be by performing step b, further really
Whether the fixed corresponding member function of method nodes 1 there occurs that code is changed.
If b, target method nodes are found, according to the byte code sequence of the method nodes and the target
The byte code sequence of method nodes, calculates Levenstein distance, if Levenstein distance is more than or equal to pre- gating
Limit value, then be labeled as first attribute, if the Levenstein by the change attribute of the corresponding member function of method nodes
Distance is less than predetermined threshold value, then the change attribute of the corresponding member function of method nodes is labeled as into second attribute.
In the embodiment of the present invention, Levenstein distance can be used for weighing the similarity between two byte code sequences.Survey
Example screening unit on probation, can after it is determined that there is the target method node of the same name with method nodes 1 in the second metadata set
According to assignment algorithm, to calculate between the byte code sequence of method nodes 1 and the byte code sequence of target method nodes
Levenstein is apart from D.
If D is more than or equal to predetermined threshold value, illustrate the byte code sequence and target method of method nodes 1
Similarity is relatively low between the byte code sequence of node, it is believed that the corresponding member function of method nodes 1 there occurs code
Change.In this case, test case screening unit can mark the change attribute of the corresponding member function of method nodes 1
For the first attribute (such as True).
And if D is less than predetermined threshold value, then illustrate the byte code sequence and target method nodes of method nodes 1
Similarity is higher between byte code sequence, it is believed that code change does not occur for the corresponding member function of method nodes 1, this
In the case of, the change attribute of the corresponding member function of method nodes 1 can be labeled as second by test case screening unit
Attribute (such as False).
It should be noted that step a to step b is by taking the method nodes 1 under class nodes 1 as an example, to the method
Node 1 enters the process of line code analysis on altered project.In the embodiment of the present invention, test case screening unit is needed under class nodes 1
Each method nodes enter line code analysis on altered project, that is, perform step a to step b, until the class nodes 1 under it is many
Individual method nodes are all traveled through, and just complete to enter the class nodes 1 process of line code analysis on altered project.
Step 303 to step 304 is the process that variance analysis is carried out to the first metadata set and the second metadata set.In order to
The concrete analysis process of each class nodes is embodied, in above-mentioned steps, is with the class nodes 1 in the first metadata set
Example, the analysis process to the class nodes 1 is illustrated, and the analysis process of other nodes is with being somebody's turn to do in first metadata set
The analysis process of class nodes 1 is similarly.Test case screening unit is needed to each class nodes in the first metadata set
Analyzed, that is, perform step 303 to step 304, until multiple class nodes in the first metadata set are all traveled through
Afterwards, then subsequent step 305 is performed.Due to including multiple member functions under each class nodes, by traveling through the first metadata set
In all class nodes, all members that code is changed in multiple class nodes of current compiling generation can be obtained
Function.
Show it should be noted that the variance analysis process of step 303 to step 304 is one of the embodiment of the present invention
Example, it is, of course, also possible to realize by other means in the class nodes and the second metadata set in the first metadata set
Class nodes carry out the process of variance analysis, and the embodiment of the present invention is not limited this.
The 305th, change attribute in multiple class nodes of current compiling generation is labeled as to all member's letters of the first attribute
Number, is retrieved as multiple member functions that code is changed, and be based on and the one-to-one test case of the plurality of member function
The test use cases of generation are tested.
In the embodiment of the present invention, test case screening unit is by above-mentioned steps 303 to step 304, to first yuan of number
Variance analysis has been carried out according to the class nodes in the class nodes and second metadata set of concentration, and with the first attribute to generation
The member function that code is changed is marked.Therefore, the institute that test case screening unit will can be marked with the first attribute
There is member function, be retrieved as multiple member functions that code is changed.
In a kind of possible implementation, the generating process of the test use cases can include:Become for the code
Each member function in multiple member functions more, according to the member function and specified call relation, from test case library
Target detection use-case is filtered out, the target detection use-case is the test case for calling the member function to be tested;Will be the plurality of
The target detection use-case of member function is retrieved as the test use cases.
For example, test case screening unit can be stored with, this specifies call relation, for indicating member function with calling
Corresponding relation between the test case that the member function is tested.Test case screening unit can be specified according to this and called
Multiple member functions that relation and the code are changed, determine multiple target detection use-cases, are then obtained from test case library
These target detection use-cases are taken, and then these target detection use-cases are performed into these test cases as the test use cases
To complete test.
It should be noted that above-mentioned be achieved in that exemplified by specifying call relation and test case to be stored separately is said
It is bright, it is stored in fact, this specifies call relation and test case to correspond in test case library.Accordingly for generation
Each member function that code is changed, test case screening unit directly can be got and the member from test case library
The corresponding test case of function.
Referring to Fig. 5, in order to more clearly embody method of testing provided in an embodiment of the present invention, using the flow shown in Fig. 5
Content in figure, all processes of embodiment above-mentioned steps 301 to step 305, Fig. 5 is entered in above-mentioned steps 301 into step 305
Explanation is gone, will not be described here.
Method provided in an embodiment of the present invention, by the class nodes and the second metadata set in the first metadata set
In class nodes carry out variance analysis, to obtain multiple member functions that code is changed, and then be directed to the plurality of member
Function, is obtained and the one-to-one test case of the plurality of member function, and according to these Test cases technology test use cases
Tested.Above-mentioned technical proposal can accurately reflect which member function there occurs that code is changed, according to these members
The test case that function is chosen is with strong points, it is possible to achieve the specific aim test of member function rank, improves testing efficiency.
Fig. 6 is a kind of structural representation of test device based on code analysis on altered project provided in an embodiment of the present invention.Ginseng
According to Fig. 6, the device includes generation module 601, analysis module 602 and test module 603:
Generation module 601, for any time before multiple class class files according to current compiling generation and current compiling
Multiple class files of generation are compiled, the first metadata set and the second metadata set of tree, two members are generated respectively
Data set includes multiple method nodes under multiple class nodes, and the multiple class nodes, each class nodes
One class file of correspondence, one member function of each method nodes correspondence;
Analysis module 602, for the variance analysis of first metadata set and second metadata set, obtaining code hair
The multiple member functions changed more;
Test module 603, for based on the test case with the one-to-one Test cases technology of the plurality of member function
Collection is tested.
Alternatively, referring to Fig. 7, the analysis module 602 includes:
Submodule is searched, for for any class nodes in first metadata set, reading the class nodes
Title, searches target class nodes, the title phase of target class nodes and the class nodes in second metadata set
Together;
Submodule is marked, if for searching less than target class nodes, by all members under the class nodes
The change attribute of function is labeled as the first attribute, and first attribute is used to indicate occur code change.
Alternatively, the lookup submodule, if it were additionally operable to find target class nodes, and the class nodes would be plucked
Want information identical with the summary info of target class nodes, then for each method nodes under the class nodes, read
Take the title of the method nodes, in second metadata set search target method nodes, target method nodes with
The title of the method nodes is identical;
Submodule is marked, it is if being additionally operable to search less than target method nodes, the method nodes is corresponding
The change attribute of method is labeled as first attribute.
Alternatively, referring to Fig. 8, the analysis module 602 also includes calculating sub module:
The calculating sub module, if for finding target method nodes, according to the byte of the method nodes
The byte code sequence of code sequence and target method nodes, calculates Levenstein distance;
If Levenstein distance is more than or equal to predetermined threshold value, by the corresponding method of method nodes
Change attribute and be labeled as first attribute;
If Levenstein distance is less than predetermined threshold value, by the change attribute of the corresponding method of method nodes
Labeled as second attribute.
In the embodiment of the present invention, by the class in the class nodes and the second metadata set in the first metadata set
Node carries out variance analysis, to obtain multiple member functions that code is changed, and then for the plurality of member function, obtains
With the one-to-one test case of the plurality of member function, and tested according to these Test cases technology test use cases.
Above-mentioned technical proposal can accurately reflect which member function there occurs that code is changed, and be chosen according to these member functions
Test case is with strong points, it is possible to achieve the specific aim test of member function rank, improves testing efficiency.
It should be noted that:The test device based on code analysis on altered project that above-described embodiment is provided is changed based on code
During the test of analysis, only with the division progress of above-mentioned each functional module for example, in practical application, can incite somebody to action as needed
Above-mentioned functions distribution is completed by different functional modules, i.e., the internal structure of equipment is divided into different functional modules, with complete
Into all or part of function described above.In addition, the test device based on code analysis on altered project that above-described embodiment is provided
Belong to same design with the method for testing embodiment based on code analysis on altered project, it implements process and refers to embodiment of the method,
Here repeat no more.
Fig. 9 is a kind of block diagram of test device 900 based on code analysis on altered project provided in an embodiment of the present invention.Reference picture
9, device 900 includes processing assembly 9001, and it further comprises one or more processors, and as representated by memory 9002
Memory resource, for store can by the execution of processing assembly 9001 instruction, such as application program.Deposited in memory 9002
The application program of storage can include it is one or more each correspond to the module of one group of instruction.In addition, processing assembly
9001 are configured as execute instruction, to perform the above-mentioned method of testing based on code analysis on altered project.
Device 900 can also include the power management that a power supply module 9003 is configured as performs device 900, and one has
Line or radio network interface 9004 are configured as device 900 being connected to network, and input and output (I/O) interface 9005.
Device 900 can be operated based on the operating system for being stored in memory 9002, such as Windows ServerTM, Mac OS XTM,
UnixTM,LinuxTM, FreeBSDTMOr it is similar.
One of ordinary skill in the art will appreciate that realizing that all or part of step of above-described embodiment can be by hardware
To complete, the hardware of correlation can also be instructed to complete by program, described program can be stored in a kind of computer-readable
In storage medium, storage medium mentioned above can be read-only storage, disk or CD etc..
The foregoing is only presently preferred embodiments of the present invention, be not intended to limit the invention, it is all the present invention spirit and
Within principle, any modification, equivalent substitution and improvements made etc. should be included in the scope of the protection.
Claims (10)
1. a kind of method of testing based on code analysis on altered project, it is characterised in that methods described includes:
According to multiple class of any compiling generation before multiple class class files of current compiling generation and current compiling
File, generates the first metadata set and the second metadata set of tree respectively, and two metadata sets include multiple
Multiple method nodes under class nodes, and the multiple class nodes, one class text of each class nodes correspondence
Part, one member function of each method nodes correspondence;
With the variance analysis of first metadata set and second metadata set, multiple member's letters of code change are obtained
Number;
Tested based on the test use cases with the one-to-one Test cases technology of the multiple member function.
2. according to the method described in claim 1, it is characterised in that for first metadata set and second metadata
Concentrate, the generating process of any piece of metadata collection includes:
Multiple class files of parsing compiling generation, obtain the title and summary info of the multiple class files and every
The title and byte code sequence for multiple member functions that individual class files are included;
Title and summary info based on the multiple class files, constitute multiple class nodes, for each class texts
Part, the title and byte code sequence of the multiple member functions included based on the class files constitute multiple method nodes,
And using the multiple method nodes as the corresponding class nodes of the class files child node.
3. according to the method described in claim 1, it is characterised in that described with first metadata set and the binary number
According to the variance analysis of collection, specifically include:
For any class nodes in first metadata set, the title of the class nodes is read, described second
Target class nodes are searched in metadata set, the target class nodes are identical with the title of the class nodes;
If searched less than the target class nodes, by the change attribute mark of all member functions under the class nodes
The first attribute is designated as, first attribute is used to indicate occur code change.
4. method according to claim 3, it is characterised in that described to search target in second metadata set
After class nodes, methods described also includes:
If finding the target class nodes, the summary info of the class nodes and the target class
Whether the summary info of node is identical;
If identical, the change attribute of all member functions under the class nodes is labeled as the second attribute, second category
Property be used for indicate code change does not occur;
If it is different, then to the method nodes under the method nodes under the class nodes and the target class nodes
Carry out variance analysis.
5. method according to claim 4, it is characterised in that the method nodes under the class nodes and
Method nodes under the target class nodes, which carry out variance analysis, to be included:
For each method nodes under the class nodes, the title of the method nodes is read, at described second yuan
Target method nodes are searched in data set, the target method nodes are identical with the title of the method nodes;
If searched less than the target method nodes, by the change attribute of the corresponding member function of the method nodes
Labeled as first attribute.
6. method according to claim 5, it is characterised in that described to search target in second metadata set
After method nodes, methods described also includes:
If finding the target method nodes, according to the byte code sequence and the target of the method nodes
The byte code sequence of method nodes, calculates Levenstein distance;
If the Levenstein distance is more than or equal to predetermined threshold value, by the corresponding member's letter of the method nodes
Several change attributes is labeled as first attribute;
If the Levenstein distance is less than predetermined threshold value, by the change of the corresponding member function of the method nodes
Attribute is labeled as second attribute.
7. a kind of test device based on code analysis on altered project, it is characterised in that described device includes:
Generation module, for any compiling life before multiple class class files according to current compiling generation and current compiling
Into multiple class files, respectively generate tree the first metadata set and the second metadata set, two metadata sets
Include multiple method nodes under multiple class nodes, and the multiple class nodes, each class nodes correspondence one
Individual class files, one member function of each method nodes correspondence;
Analysis module, for the variance analysis of first metadata set and second metadata set, obtaining code
Multiple member functions of change;
Test module, for based on the progress of the test use cases of the one-to-one Test cases technology of the multiple member function
Test.
8. device according to claim 7, it is characterised in that the analysis module includes:
Submodule is searched, for for any class nodes in first metadata set, reading the class nodes
Title, searches target class nodes, the target class nodes and the class nodes in second metadata set
Title is identical;
Submodule is marked, if for searching less than the target class nodes, by all members under the class nodes
The change attribute of function is labeled as the first attribute, and first attribute is used to indicate occur code change.
9. device according to claim 8, it is characterised in that the lookup submodule, if being additionally operable to find described
Target class nodes, and the summary info of the class nodes is identical with the summary info of the target class nodes, then it is right
In each method nodes under the class nodes, the title of the method nodes is read, in second metadata set
Middle lookup target method nodes, the target method nodes are identical with the title of the method nodes;
Submodule is marked, it is if being additionally operable to search less than the target method nodes, the method nodes is corresponding
The change attribute of member function is labeled as first attribute.
10. device according to claim 9, it is characterised in that the analysis module also includes calculating sub module:
The calculating sub module, if for finding the target method nodes, according to the word of the method nodes
The byte code sequence of code sequence and the target method nodes is saved, Levenstein distance is calculated;
The mark submodule, will be described if being additionally operable to the Levenstein distance is more than or equal to predetermined threshold value
The change attribute of the corresponding member function of method nodes is labeled as first attribute;
The mark submodule, if being additionally operable to the Levenstein distance is less than predetermined threshold value, the method is saved
The change attribute of the corresponding member function of point is labeled as second attribute.
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 true CN107015909A (en) | 2017-08-04 |
CN107015909B 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) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117215965A (en) * | 2023-11-09 | 2023-12-12 | 恒生电子股份有限公司 | Test case identification-based test method and device, electronic equipment and medium |
Family Cites Families (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CA2147036A1 (en) * | 1994-05-16 | 1995-11-17 | Yih-Farn Robin Chen | System and method for selective regression testing |
CN103678097A (en) * | 2012-09-05 | 2014-03-26 | 百度在线网络技术(北京)有限公司 | Method and device for selecting regression test case |
CN103617122B (en) * | 2013-12-12 | 2016-03-30 | 用友网络科技股份有限公司 | A kind of comparison method of source code |
CN105760288B (en) * | 2014-12-15 | 2019-02-01 | 阿里巴巴集团控股有限公司 | Test the method and device of revised application program |
-
2017
- 2017-03-31 CN CN201710211420.8A patent/CN107015909B/en active Active
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117215965A (en) * | 2023-11-09 | 2023-12-12 | 恒生电子股份有限公司 | Test case identification-based test method and device, electronic equipment and medium |
CN117215965B (en) * | 2023-11-09 | 2024-02-27 | 恒生电子股份有限公司 | Test case identification-based test method and device, electronic equipment and medium |
Also Published As
Publication number | Publication date |
---|---|
CN107015909B (en) | 2020-03-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP3014479B1 (en) | Omega names: name generation and derivation | |
CN109359094B (en) | Distributed system log full-link tracking method and device | |
CN108345485B (en) | Identification method and device for interface view | |
CN106708565A (en) | Method and device for removing useless picture resources in APK (Android Package) | |
CN110866029B (en) | sql statement construction method, device, server and readable storage medium | |
US11681606B2 (en) | Automatic configuration of logging infrastructure for software deployments using source code | |
CN111984436A (en) | Data acquisition system | |
CN112925757A (en) | Method, equipment and storage medium for tracking operation log of intelligent equipment | |
CN110543427A (en) | Test case storage method and device, electronic equipment and storage medium | |
Svajlenko et al. | Big data clone detection using classical detectors: an exploratory study | |
CN112433991A (en) | Problem positioning method and device | |
CN103530369A (en) | De-weight method and system | |
CN107015909A (en) | Method of testing and device based on code analysis on altered project | |
CN116627818A (en) | Test case multiplexing method based on program path similarity | |
US20090064092A1 (en) | Visual programming language optimization | |
CN115437640A (en) | Method for quickly compiling engineering code | |
CN113821486B (en) | Method and device for determining dependency relationship between pod libraries and electronic equipment | |
CN113495723B (en) | Method, device and storage medium for calling functional component | |
CN115729797A (en) | Code similarity function detection method and device, electronic equipment and storage medium | |
CN111694728A (en) | Automatic generation method and device of script | |
CN111352824B (en) | Test method and device and computer equipment | |
CN113742208A (en) | Software detection method, device, equipment and computer readable storage medium | |
US20190294534A1 (en) | Program usability performance classification | |
CN114969131B (en) | Information query method, device and equipment | |
Berztiss | Depth-first K-trees and critical path analysis |
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 Visual Technology Co., Ltd. Address before: 266555 Qingdao economic and Technological Development Zone, Shandong, Hong Kong Road, No. 218 Patentee before: QINGDAO HISENSE ELECTRONICS Co.,Ltd. |