CN102436417A - Code and function covering mapping system and covering mapping method thereof - Google Patents

Code and function covering mapping system and covering mapping method thereof Download PDF

Info

Publication number
CN102436417A
CN102436417A CN2011102957593A CN201110295759A CN102436417A CN 102436417 A CN102436417 A CN 102436417A CN 2011102957593 A CN2011102957593 A CN 2011102957593A CN 201110295759 A CN201110295759 A CN 201110295759A CN 102436417 A CN102436417 A CN 102436417A
Authority
CN
China
Prior art keywords
code
control
function
covering
module
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2011102957593A
Other languages
Chinese (zh)
Other versions
CN102436417B (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.)
China Software Evaluation Center
Original Assignee
Individual
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 Individual filed Critical Individual
Priority to CN201110295759.3A priority Critical patent/CN102436417B/en
Publication of CN102436417A publication Critical patent/CN102436417A/en
Application granted granted Critical
Publication of CN102436417B publication Critical patent/CN102436417B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a code and function covering mapping system which structurally comprises a white box testing tool, a code covering information extraction module, a code and control mapping processing module and a code covering and function covering mapping module. The invention also discloses a code and function covering mapping method and has the technical scheme that: a bridge between a white box testing and a black box testing can be set up, respective specialty of the white box testing and the black box testing can be fully exerted, and sufficiency and efficiency for a testing can be improved.

Description

Code and function covering mappings system and covering mappings method thereof
Technical field
The present invention relates to the software function field tests, particularly a kind of code and function covering mappings system and covering mappings method thereof.
Background technology
White-box testing and Black-box Testing are two kinds of main method that software test is adopted.In the white-box testing field, in order accurately to grasp the coverage condition of test case, released business-like testing tool successively to code, representational have TestBed instrument, a CodeTest instrument etc.These instruments adopt program plug-in mounting technology; Can accurately demonstrate the information such as statement, branch and path that test case covers; According to these information; The tester can design new test case and cover those not by the code that current test case covered, thereby satisfies the testing adequacy requirement.The advantage of this method is intuitively to show the coverage condition of test case to code; Its shortcoming is when the new test case of design covers the code that is not capped; Need tester's reading code, have only code is analyzed, could design the test case that makes new advances.This requires the tester to have higher program design level on the one hand, need spend a large amount of energy and times on the other hand.
Corresponding with the white-box testing method is the Black-box Testing method; This method is only paid close attention to the function of software and is not considered the program code structure, the time only considers that in test test case is indifferent to its coverage condition to the bottom program code to the coverage condition of software function.The advantage of this method is directly perceived, convenient, and its shortcoming shows three aspects, the one, and it is thicker to cover granularity.Satisfy the test of function coverage criteria and not necessarily can satisfy the code coverage criteria; The 2nd, can't obtain the function coverage condition corresponding through the code coverage information with it.Although the tester has obtained unlapped code information through the white-box testing instrument, how to cover these codes and remain a difficult problem from the new test case of functional perspective design; The 3rd, can't discern that variation has taken place those bottom program codes and software function that software function does not change.At present, test case can only be leaned on complicate statistics to the coverage information of software function, the aid of commercial-free.
White-box testing and Black-box Testing are two kinds of indispensable in software test methods, but owing to lack effective method, these two kinds of method of testings are in the state of isolating always, have had a strong impact on testing adequacy and efficient.
Summary of the invention
The technical matters that the present invention solved provides a kind of code and function covering mappings system, can build bridge between white-box testing and the Black-box Testing, gives full play to white-box testing and Black-box Testing speciality separately, improves testing adequacy and efficient.
Technical scheme is following:
A kind of code and function covering mappings system; Comprise the white-box testing instrument; Said white-box testing instrument is used to extract and demonstrate the code that test case covers; Comprise that also code coverage information extraction module, code and control mapping treatment module and code cover and function covering mappings module, wherein
Code coverage information extraction module; Be used to receive the code coverage information that sends from said white-box testing instrument; And from said code coverage information, extract the program statement that is covered, and said program statement is sent to said code covering and function covering mappings module;
Code and control mapping treatment module; Be used for routine analyzer statement source program code, make up syntax tree and symbol table; Realize the mapping of source program code and software interface control on this basis, and mapping relations are sent to code covering and function covering mappings module;
Code covers and function covering mappings module, is used for converting said program statement into the function coverage information according to the mapping relations of said source program code and software interface control.
Further: when said code and control mapping treatment module are carried out morphology and grammatical analysis; Type Principles & Technology of Compiler Design are adopted in said morphology and grammatical analysis; The tested software source code is carried out morphology and grammatical analysis, obtain said abstract syntax tree and symbol table through analysis.
Further: said code and control mapping treatment module adopt depth first search technique in graphic user interface GUI control identification process, travel through said abstract syntax tree and symbol table, obtain GUI controls all in the source code.
Further: said code and control mapping treatment module are used to generate the source code of tested program and the code control mapping table of GUI control, through in the code analysis to the statement of the definition and the use of GUI control, obtain code control mapping table.
Further: said code covers and the not covering code information of function covering mappings module according to input; Through code control mapping table is searched for; Obtain relevant unlapped graphic user interface GUI list of controls, do not cover code and scan code control mapping table through traversal and generate and do not cover the GUI list of controls.
Another technical matters that the present invention solved provides a kind of code and function covering mappings method, can build bridge between white-box testing and the Black-box Testing, gives full play to white-box testing and Black-box Testing speciality separately, improves testing adequacy and efficient.
Technical scheme is following:
A kind of code and function covering mappings method comprise:
The white-box testing instrument is used to extract and demonstrate the code coverage information of test case, and sends to code coverage information extraction module;
Code coverage information extraction module receives the code coverage information that sends from said white-box testing instrument; And from said code coverage information, extract the program statement that is covered, and said program statement is sent to said code covering and function covering mappings module;
Source program code, structure syntax tree and symbol table are realized the mapping of source program code and software interface control on this basis in code and the control mapping treatment module analysis program statement, and mapping relations are sent to code covering and function covering mappings module;
Code covering and function covering mappings module convert said program statement into the function coverage information according to the mapping relations of said source program code and software interface control.
Further: when said code and control mapping treatment module were carried out morphology and grammatical analysis, type Principles & Technology of Compiler Design were adopted in morphology and grammatical analysis, and the tested software source code is carried out morphology and grammatical analysis, obtain abstract syntax tree and symbol table through analysis.
Further: said code and control mapping treatment module adopt depth first search technique in graphic user interface GUI control identification process, travel through said abstract syntax tree and symbol table, obtain GUI controls all in the source code.
Further: said code and control mapping treatment module are used to generate the source code of tested program and the code control mapping table of GUI control, through in the code analysis to the statement of the definition and the use of GUI control, obtain code control mapping table.
Further: said code covers and the not covering code information of function covering mappings module according to input; Through code control mapping table is searched for; Obtain relevant unlapped graphic user interface GUI list of controls, do not cover code and scan code control mapping table through traversal and generate and do not cover the GUI list of controls.
Technique effect comprises:
1, the present invention mainly solves and how to convert the code coverage information into function coverage information technical matters; A kind of method that the code coverage information is converted into the function coverage information is provided; Thereby build bridge between white-box testing and the Black-box Testing; Give full play to white-box testing and Black-box Testing speciality separately, improve testing adequacy and efficient.
2, the present invention adopts code and software function mapping method; Through code control mapping table, convert the code covering into function and cover, the tester is through the function coverage information; Can design the test case that makes new advances simply, intuitively, this also is the most outstanding characteristics of the present invention.
Description of drawings
Fig. 1 is the structured flowchart of code and function covering mappings system among the present invention;
Fig. 2 is the main flow chart of code and function covering mappings method among the present invention;
Fig. 3 is the workflow diagram of code and control mapping treatment module among the present invention;
Fig. 4 is morphology and a grammatical analysis process flow diagram among the present invention;
Fig. 5 is the workflow diagram of control discrimination method among the present invention;
Fig. 6 is the groundwork process flow diagram of code control map analysis among the present invention;
Fig. 7 is that code covers the workflow diagram with the function covering mappings among the present invention;
Fig. 8 be among the present invention the 6th walk to the eighth row code abstract syntax tree;
Fig. 9 is the 22nd a capable abstract syntax tree to the 24th line code among the present invention;
Figure 10 is the pairing actual software master of a code sample interface synoptic diagram among the present invention;
Figure 11 is the pop-up window interface synoptic diagram of " test menu item 1 " guiding in the code sample of the present invention.
Embodiment
With reference to exemplary preferred embodiments and reference drawings technical scheme of the present invention is described in detail below.
As shown in Figure 1, be the structured flowchart of code and function covering mappings system among the present invention.
Code and function covering mappings system comprise: white-box testing instrument 101, code coverage information extraction module 102, code and control mapping treatment module 103 and code cover and function covering mappings module 104 4 parts.
Wherein, white-box testing instrument 101 is used to extract and demonstrate the coverage information of test case to code, and sends coverage information and give code coverage information extraction module 102, and the code coverage information comprises the information such as statement, branch and path that covered.Code coverage information extraction module 102 is used for extracting the program statement that is covered from code coverage information (can cause the statement that program execution path changes), and program statement is sent to code covering and function covering mappings module 104.Code and control mapping treatment module 103 are used to realize the mapping of source program code and software interface control; Through analyzing source program code; Make up syntax tree and symbol table; On this basis, find out the mapping relations of source program code and software interface control, and mapping relations are sent to code covering and function covering mappings module 104.Code covering and function covering mappings module 104 convert program statement into the function coverage information according to the mapping relations of source program code and software interface control.
As shown in Figure 2, be main flow chart of the present invention.
Step 201: source program code is carried out grammer and lexical analysis;
The statement that program execution path changes be can cause through analyzing, finding out in the code, syntax tree and symbol table made up.
Step 202:, adopt the method for plug-in mounting that special mark is set, as the program statement that is covered for these statements;
Step 203: carry out secondary compiling again, and will compile the code of getting well and download to and move in the target machine;
Step 204: in software running process, with the file mode record program statement that test case was covered;
Step 205:, set up source code and interface control mapping relations according to syntax tree and symbol table;
Step 206: program statement and source code and interface control mapping relations according to test case covered provide the coverage information of test case to software function.
Code and control mapping treatment module 103 are used to realize the mapping of source program code and software interface control.
As shown in Figure 3, the workflow diagram of code and control mapping treatment module 103.The workflow and each stage intermediate result of having represented code and control mapping treatment module 103 among the figure.
Step 301: code and control mapping treatment module 103 are carried out morphology and grammatical analysis.Type Principles & Technology of Compiler Design are adopted in morphology and grammatical analysis, and the tested software source code is carried out morphology and grammatical analysis, through analyzing, obtain abstract syntax tree and symbol table.
As shown in Figure 4, be morphology and grammatical analysis process flow diagram among the present invention.The fundamental purpose of this analysis is abstract syntax tree and the symbol table that obtains the tested software source code.
Definition 1: abstract syntax tree is one tree T=< V, E >, and wherein: V is the node of tree, is made up of the various syntactic structures in the source code; E is the limit of tree, is responsible for connecting various syntactic structures.
Definition 2: symbol table is a table graphic data structure, and the identifier that produces in the lexical analysis process is as the inlet of symbol table, the information that subsequent analysis obtains, as: the type of identifier, use-pattern, storage space etc. can join in the table as required.
Morphology and grammatical analysis are the bases of generating code and interface control mapping relations.This programme employing method in common is carried out morphology and grammatical analysis to the source code of tested software, is described by algorithm 2.
Algorithm 2.Lexical_Syntax_Analyze (P)
Input P: source code
Output (AST, SymTable): the abstract syntax tree of P and symbol table
1.TokenStream<-Lexical_Analyze(P)
2.(AST,SymTable)<-Syntax_Analyze(TokenStream)
3.Return(AST,SymTable)
Source code will obtain its abstract syntax tree and symbol table after process morphology and grammatical analysis.The 1st step of algorithm 2 is carried out lexical analysis to source code P, obtains the marked flows TokenStream of P; The 2nd step was that grammatical analysis is carried out on the basis with the marked flows, obtained abstract syntax tree AST and the symbol table SymTable of P; The 3rd step was returned AST and SymTable.
Step 302:GUI (Graphical User Interface is called for short GUI, and graphic user interface is claimed graphical user interface again) control identification.Adopt depth first search technique, traversal abstract syntax tree and symbol table obtain GUI control all in the source code (as: window, button etc.).
The GUI control is the imbody of software function, and software function realizes through control.The purpose of GUI control identification is all GUI controls of finding out in the program to be designed, through the analysis to abstract syntax tree and symbol table, picks out all GUI controls that is:.This step is mainly through accomplishing to the abstract syntax traversal of tree with to searching of symbol table.Main method is: with depth first method traversal abstract syntax tree, if certain leaf node is a variable, at this moment through searching symbol table, can obtain this type of variables; If the type is a GUI control type, then explain this variable described be a GUI control.
Abstract syntax tree and symbol table have all been used in GUI control identification in program compilation and this programme, but both purposes are different, and the former purpose is to generate and the optimization aim code, and the latter's purpose is to find out GUI controls all in the source code.
1, control type
Programming language is different, and the control type that it comprised is also different, is example with Java Swing, and the control that it comprised can be divided into following several types:
(1) window and window frame class: JWindow, JColorChooser, JComponent, JDesktopPane; JDialog, JEditorPane, JFileChooser, JFrame; JInternalFrame, JLayeredPane, JOptionPane, JRootPane; JScrollPane, JSplitPane, JTabbedPane;
(2) button class: JButton, JToggleButton, JCheckBox, JCheckBoxMenuItem, JComboBox, JRadioButton, JRadioButtonMenuItem;
(3) menu class: JMenu, JMenuBar, JMenuItem, JPopupMenu;
(4) text input class: JTextArea, JTextComponent, JTextField, JPasswordField;
(5) other: JTree, JViewPort, JScrollBar, JSeparator, JSlider, JSpinner, JTable, JTableHeader, JToolBar, JToolTip, JLabel, JList, JProgressBar.
Though these controls have method of application separately,, be to confirm certain variable-definition for the mode of certain control by the standard of language itself, therefore, and can be according to these standards, these controls of employing unified method identification.
2, variable-definition mode
Definition mode to control variable mainly contains 2 kinds:
(1) variable declarations
Call the turn at program design language, the existence that variable declarations is responsible for pointing out certain variable with and relevant character, but it is not carried out initialization.
For example: private javax.swing.JButton computeButton; It is the variable computeButton of javax.swing.JButton that this statement has defined type.
(2) variable-definition
Call the turn at program design language, the existence that variable-definition not only is responsible for pointing out certain variable with and relevant character, also need carry out initialization to it.
For example: javax.swing.JMenu fileMenu=newjavax.swing.JMenu ();
This statement has defined type to be the variable fileMenu of javax.swing.JMenu and to use the new statement that it has been carried out initialization.
3, control discrimination method
Through in abstract syntax tree, above-mentioned two kinds of definition modes being searched for, the content in the combined symbol table just can pick out controls all in the source code and variable thereof simultaneously.
As shown in Figure 5, be the workflow diagram of control discrimination method among the present invention.
Through traveling through abstract syntax tree and searching symbol table, can generate the GUI list of controls, can adopt algorithm 3 to express.
(AST SymTable) has described GUI control identification algorithm to algorithm 3.GEL_AST_SymTable.
Algorithm 3.GEL_AST_SymTable (AST, SymTable)
Input AST: the abstract syntax tree of source code
Input SymTable: the symbol table of source code
Output GEL: the GUI list of controls in the source code
1.GEL<-[];
2. travel through all leaf node Node of AST
3.if (LookUpType (SymTable, Node)=GUI control type)
4.GEL<-Node::GEL
5.Return?GEL
The 1st step initialization rreturn value GEL of algorithm 3 is empty tabulation; The 2nd step to the 4th step begins to travel through abstract syntax tree AST; Wherein (SymTable Node) judges whether leaf node Node is GUI control type to the 3rd step, if then in the 4th step this node is added rreturn value GEL tabulation with function LookUpType; After abstract syntax tree AST traversal was accomplished, the 5th step was returned GUI list of controls GEL.
Step 303: code control map analysis.Adopt depth first search technique, traversal abstract syntax tree and GUI list of controls, generating code control mapping table.
Code and control mapping treatment module 103 are used to generate the source code of tested program and the code control mapping table of GUI control.Through in the code analysis to the statement of the definition and the use of GUI control, obtain code control mapping table, workflow can use algorithm 1 to describe.
Algorithm 1.GetGUICodeMap (P)
Input P: source code
Output T: code control mapping table
1.(AST,SymTable)<-Lexical_Syntax_Analyze(P)
2.GUIEmtList<-GEL_AST_SymTable(AST,SymTable)
3.T<-GCM_AST_GEL(AST,GUIEmtList)
4.Return?T
The 1st step of algorithm 1 is parameter call function Lexical_Syntactax_Analyze with P (source code of tested software), obtains abstract syntax tree AST and the symbol table SymTable of P; The 2nd step was parameter call algorithm GEL_AST_SymTable with AST and SymTable, obtained the GUI list of controls GUIEmtList of P; The 3rd step was parameter call algorithm GCM_AST_GEL with AST and GUIEmtList, obtained code control mapping table T; The 4th step was returned the result.
1.GUI control statement and definition
Before using a GUI control, need define this control through the object of stating and define a control type.For example: in the code below, at first state the object menuBar of a MenuBar type, use a new statement that this object is defined then.
Figure BDA0000095618470000091
2.GUI control uses
Use to the GUI control is to realize through the calling of method to control object.Button control with JButton type commonly used is an example, when button is pressed, can carry out certain user-defined function usually.The user is through accomplishing above-mentioned function to ActionLisener function of the addActionListener of button function passes.In the ActionListener function; The user need realize the actionPerformed function; This function is exactly the action that button is carried out when being pressed, if the user hopes to carry out own certain function that defines, then can this function be joined in the actionPerformed function.
For example, in below the code
Figure BDA0000095618470000101
OpenButton is the button of a JButton type; Through the openButtonActionPerformed function being joined in the actionPerformed function body in the ActionListener function, can realize when the openButton button is pressed, calling the openButtonActionPerformed function.
As shown in Figure 6, be the groundwork process flow diagram of code control map analysis among the present invention, process is described by algorithm 4.
Algorithm 4.GCM_AST_GEL (AST, GUIEmtList)
Input AST: the abstract syntax tree of source code
Input GUIEmtList: the GUI list of controls in the source code
Output T: the two-way mapping table of code control
1.T<-Null
2. travel through all the GUI control GEmt1 among the GUIEmtList
3 traversal AST
4.GCode < the code segment corresponding among the AST with GEmt1
5.T<-T::[GEmt1,GCode]
6.Return?T
The course of work of algorithm 4 is: the 1st step was initialized as sky with rreturn value T; All GUI control GEmt1 among the 2nd step traversal GUIEmtList; The 3rd step traversal abstract syntax tree AST; The 4th step was found the corresponding source code fragment of GEmt1 control; The mapping of the 5th step with GEmt1 and GCode joins among the T; The 6th step was returned the result.
Code covers with function covering mappings module 104 and is used for converting the code coverage information into the function coverage information.In operational process; White-box testing instrument 101 can obtain the source program code that test case covers; These coverage informations are preserved with file mode, and its file layout of different tools is different, use Codetest instrument commonly used in this preferred embodiment; Through analyzing its idb file, obtain the code coverage information.
As shown in Figure 7; Be that code covers the workflow diagram with the function covering mappings among the present invention; Code covers and the not covering code information of function covering mappings module 104 according to input, through code control mapping table is searched for, obtains relevant unlapped GUI list of controls.Do not cover code and scan code control mapping table through traversal, can generate and not cover the GUI list of controls.
(NCC T) has described and has not covered GUI list of controls generating algorithm algorithm 5.NCGL_NCC_T.
Algorithm 5.NCGL_NCC_T (NCC, T)
Input NCC: do not cover code line number
Input T: code control mapping table
Output NCGL: do not cover the GUI list of controls
1.NCGL<-[];
2. travel through all code snippets among the NCC
3.NCG < the GUI control corresponding among the T with NCC
4.NCGL<-NCG::NCGL
5.Return?NCGL
The 1st step initialization rreturn value NCGL of algorithm 5 is empty tabulation; The 2nd step to the 4th step begins to travel through NCC; Wherein the 3rd step was sought corresponding GUI control from T; The 4th step added rreturn value NCGL tabulation with this GUI control; After the NCC traversal is accomplished, the 5th step will not cover GUI list of controls NCGL and will return.
With a specific embodiment, technical scheme of the present invention is done further checking below.Utilize the present invention,, generate its corresponding function and cover according to the code information that test case covered.
1?public?class?AnaSwingFirstView?extends?FrameView{
2?private?void?initComponents(){
3 menuBar=newjavax.swing.JMenuBar () have defined a menu bar manuBar;
4 javax.swing.JMenu fileMenu=new javax.swing.JMenu () have defined a menu fileMenu;
5 javax.swing.JMenuItem exitMenuItem=new javax.swing.JMenuItem () have defined a menu item exitMenuItem;
6 testMenu=newjavax.swing.JMenu () have defined menu testMenu;
7 popTestMenuItem1=new javax.swing.JMenuItem () have defined menu item popTestMenuItem1;
8 popTestMenuItem2=new javax.swing.JMenuItem () have defined menu item popTestMenuItem2;
9 menuBar.setName (" menuBar "); Set the character display of menuBar;
10 fileMenu.add (exitMenuItem) join fileMenu as its menu item with exitMenuItem;
11 fileMenu.setText (resourceMap.getString (" fileMenu.text ")), the character display of fileMenu is set to fileMenu.text (file);
12 exitMenuItem.setText (resourceMap.getString (" exitMenuItem.text ")), the character display of exitMenuItem is set to exitMenuItem.text (withdrawing from);
13 menuBar.add (fileMenu) join menuBar as its menu with fileMenu;
14 testMenu.setText (resourceMap.getString (" testMenu.text ")), the character display of testMenu is set to testMenu.text (test menu);
15
PopTestMenuItem1.setText (resourceMap.getString (" popTestMenuItem1.text ")), the character display of popTestMenuItem1 is set to popTestMenuItem1.text (test menu item 1);
16 popTestMenuItem1.addActionListener (new java.awt.event.ActionListener (), defined performed operation when clicking as popTestMenuItem1;
17?public?void?actionPerformed(java.awt.event.ActionEvent?evt){
18?popTestMenuItem1?ActionPerPermed(evt);
19?}
20?});
21
PopTestMenuItem2.setText (resourceMap.getString (" popTestMenuItem2.text ")), the character display of popTestMenuItem2 is set to popTestMenuItem2.text (test menu item 2);
22 testMenu.add (popTestMenuItem1) join testMenu as its menu item with popTestMenuItem1;
23 testMenu.add (popTestMenuItem2) join testMenu as its menu item with popTestMenuItem2;
24 menuBar.add (testMenu) join menuBar as its menu with testMenu;
25?}
26?private?void
PopTestMenuItem1ActionPerformed (java.awt.event.ActionEvent evt), defined popTestMenuItem 1ActionPerformed function;
27?openTest(evt);
28?}
29 private Void openTest (java.awt.event.ActionEvent evt), defined the openTest function;
30 JFrame popFrame=new JFrame (" pop-up window ") have defined pop-up window (popFrame);
31 JButton pfButton1=new JButton (" testing button ") defined button testButton, and its character display are set to testing button;
32 popFrame.add (pfButton1) join pfButton1 among the popFrame;
33 popFrame.setVisible (true) are made as popFrame visible.
34?}
35?}
As shown in Figure 8, be among the present invention the 6th walk to the eighth row code abstract syntax tree, as shown in Figure 9, be among the present invention the 22nd row to the abstract syntax tree of the 24th line code.At first, use algorithm in this programme more than 2 pairs code sample carry out morphology and grammatical analysis, obtain its abstract syntax tree (Fig. 8, Fig. 9) and symbol table (table 1).
Table 1: the symbol table of example code segment
Identifier Type The definition number of being expert at
menuBar JMenuBar 3
fileMenu JMenu 4
exitMenuItem JMenuItem 5
testMenu JMenu 6
popTestMenuItem?1 JMenuItem 7
popTestMenuItem?2 JMenuItem 8
popFrame JFrame 30
pfButton?1 JButton 31
Table 1 has provided the symbol table of example code segment.Wherein, have 8 symbols, write down their type in the symbol table and in source code by the row in when definition number.
According to the abstract syntax tree and the symbol table of example code segment, use the algorithm 3 in this programme to carry out the identification of GUI control, thereby obtain its GUI list of controls, as shown in table 2.
Table 2:GUI list of controls
Identifier Character display Type
menuBar Do not have JMenuBar
fileMenu File JMenu
exitMenuItem Withdraw from JMenuItem
testMenu Test menu JMenu
popTestMenuItem?1 Test menu item 1 JMenuItem
popTestMenuItem?2 Test menu item 2 JMenuItem
popFrame Pop-up window JFrame
pfButton?1 Testing button JButton
Shown in figure 10, be the pairing actual software master of code sample interface synoptic diagram among the present invention.Shown in figure 11, be the pop-up window interface synoptic diagram of " test menu item 1 " guiding in the code sample of the present invention.Clicking " test menu item 1 " afterwards, will eject a window, have one " testing button " in this window.
According to its abstract syntax tree and GUI list of controls, use the algorithm 4 generating code control mapping tables in this programme, as shown in table 3.
Table 3: code control mapping table
Figure BDA0000095618470000151
When using white-box testing instrument 101 to carry out the code coverage test, after carrying out other control of clicking except that " test menu item 1 ", the code coverage result that white-box testing instrument 101 provides is shown in following code segment.
1?public?class?AnaSwingFirstView?extends?FrameView{
2?private?void?initComponents(){
3 menuBar=newjavax.swing.JMenuBar () have defined a menu bar manuBar;
4 javax.swing.JMenu fileMenu=new javax.swing.JMenu () have defined a menu fileMenu;
5 javax.swing.JMenuItem exitMenuItem=new javax.swing.JMenuItem () have defined a menu item exitMenuItem;
6 testMenu=newjavax.swing.JMenu () have defined menu testMenu;
7 popTestMenuItem1=new javax.swing.JMenuItem () have defined menu item popTestMenuItem1;
8 popTestMenuItem2=new javax.swing.JMenuItem () have defined menu item popTestMenuItem2;
9 menuBar.setName (" menuBar "); Set the character display of menuBar;
10 fileMenu.add (exitMenuItem) join fileMenu as its menu item with exitMenuItem;
11 fileMenu.setText (resourceMap.getString (" fileMenu.text ")), the character display of fileMenu is set to fileMenu.text (file);
12 exitMenuItem.setText (resourceMap.getString (" exitMenuItem.text ")), the character display of exitMenuItem is set to exitMenuItem.text (withdrawing from);
13 menuBar.add (fileMenu) join menuBar as its menu with fileMenu;
14 testMenu.setText (resourceMap.getString (" testMenu.text ")), the character display of testMenu is set to testMenu.text (test menu);
15
PopTestMenuItem1.setText (resourceMap.getString (" popTestMenuItem1.text ")), the character display of popTestMenuItem1 is set to popTestMenuItem1.text (test menu item 1);
16 popTestMenuItem1.addActionListener (new java.awt.event.ActionListener (), defined performed operation when clicking as popTestMenuItem1;
17?public?void?actionPerformed(java.awt.event.ActionEvent?evt){
18?popTestMenuItem1ActionPerformed(evt);
19?}
20?});
21
PopTestMenuItem2.setText (resourceMap.getString (" popTestMenuItem2.text ")), the character display of popTestMenuItem2 is set to popTestMenuItem2.text (test menu item 2);
22 testMenu.add (popTestMenuItem1) join testMenu as its menu item with popTestMenuItem1;
23 testMenu.add (popTestMenuItem2) join testMenu as its menu item with popTestMenuItem2;
24 menuBar.add (testMenu) join menuBar as its menu with testMenu;
25?}
26 private void popTestMenuItem1ActionPerformed (java.awt.event.ActionEvent evt), defined the popTestMenuItem1ActionPerformed function;
27?openTest(evt);
28?}
29 private void openTest (java.awt.event.ActionEvent evt), defined the openTest function;
30 JFrame popFrame=new JFrame (" pop-up window ") have defined pop-up window (popFrame);
31 JButton pfButton1=new JButton (" testing button ") defined button testButton, and its character display are set to testing button;
32 popFrame.add (pfButtonl) join pfButton1 among the popFrame;
33 popFrame.setVisible (true) are made as popFrame visible.
34?}
35?}
Through white-box testing instrument 101, the code that the tester can intuitively grasp test case and covered.Wherein the 1-28 rower is green (representing with roman among this paper), and expression has covered; And the 29-34 rower is red (representing with italic among this paper), and expression does not cover as yet.On this basis, according to the coverage rate requirement, through the manual analysis code, design new test case and cover those codes that are not capped, owing to need carry out manual analysis to code, therefore, this method one is high to tester's requirement, the 2nd, and efficient is low.In order to address these problems; The present invention adopts code and software function mapping method; Through before the code control mapping table that obtains, code covered convert function into and cover, the tester is through the function coverage information; Can design the test case design that makes new advances simply, intuitively, this also is the most outstanding characteristics of the present invention.
The step that realizes such scheme is following.
Step 1: through inquiry code control mapping table (table 3), use algorithm 5, can obtain: the 29-34 line code is corresponding to " test menu item 1 ".That is: the test case of having carried out does not cover some function of " test menu item 1 ", therefore, needs to the new test case of this control design.
Step 2: cover " test menu item 1 ", the new test case that needs is: test menu-test menu item 1->ejector button.That is: at first click " test menu ", click then " test menu item 1 ", click then " ejector button ".
In sum, morphology and grammatical analysis, the identification of GUI control and 3 steps of code control map analysis through to source code just can obtain code control mapping table; Then; The code control mapping table that provides in the unlapped code information that provides according to the white-box testing instrument and this programme; Just can obtain unlapped software function, in view of the above, the tester can design the new test case that covers these functions easily.

Claims (10)

1. code and function covering mappings system; Comprise the white-box testing instrument; Said white-box testing instrument is used to extract and demonstrate the code coverage information of test case; It is characterized in that: comprise that also code coverage information extraction module, code and control mapping treatment module and code cover and function covering mappings module, wherein
Code coverage information extraction module; Be used to receive the code coverage information that sends from said white-box testing instrument; And from said code coverage information, extract the program statement that is covered, and said program statement is sent to said code covering and function covering mappings module;
Code and control mapping treatment module; Be used for routine analyzer statement source program code, make up syntax tree and symbol table; Realize the mapping of source program code and software interface control on this basis, and mapping relations are sent to code covering and function covering mappings module;
Code covers and function covering mappings module, is used for converting said program statement into the function coverage information according to the mapping relations of said source program code and software interface control.
2. code as claimed in claim 1 and function covering mappings system; It is characterized in that: when said code and control mapping treatment module are carried out morphology and grammatical analysis; Type Principles & Technology of Compiler Design are adopted in said morphology and grammatical analysis; The tested software source code is carried out morphology and grammatical analysis, obtain said abstract syntax tree and symbol table through analysis.
3. code as claimed in claim 2 and function covering mappings system; It is characterized in that: said code and control mapping treatment module adopt depth first search technique in graphic user interface GUI control identification process; Travel through said abstract syntax tree and symbol table, obtain GUI controls all in the source code.
4. code as claimed in claim 3 and function covering mappings system; It is characterized in that: said code and control mapping treatment module are used to generate the source code of tested program and the code control mapping table of GUI control; Through in the code analysis to the statement of the definition and the use of GUI control, obtain code control mapping table.
5. code as claimed in claim 1 and function covering mappings system; It is characterized in that: said code covers and the not covering code information of function covering mappings module according to input; Through code control mapping table is searched for; Obtain relevant unlapped graphic user interface GUI list of controls, do not cover code and scan code control mapping table through traversal and generate and do not cover the GUI list of controls.
6. code and function covering mappings method comprise:
The white-box testing instrument is used to extract and demonstrate the code coverage information of test case, and sends to code coverage information extraction module;
Code coverage information extraction module receives the code coverage information that sends from said white-box testing instrument; And from said code coverage information, extract the program statement that is covered, and said program statement is sent to said code covering and function covering mappings module;
Source program code, structure syntax tree and symbol table are realized the mapping of source program code and software interface control on this basis in code and the control mapping treatment module analysis program statement, and mapping relations are sent to code covering and function covering mappings module;
Code covering and function covering mappings module convert said program statement into the function coverage information according to the mapping relations of said source program code and software interface control.
7. code as claimed in claim 6 and function covering mappings method; It is characterized in that: when said code and control mapping treatment module are carried out morphology and grammatical analysis; Type Principles & Technology of Compiler Design are adopted in morphology and grammatical analysis; The tested software source code is carried out morphology and grammatical analysis, obtain abstract syntax tree and symbol table through analysis.
8. code as claimed in claim 7 and function covering mappings method; It is characterized in that: said code and control mapping treatment module adopt depth first search technique in graphic user interface GUI control identification process; Travel through said abstract syntax tree and symbol table, obtain GUI controls all in the source code.
9. code as claimed in claim 8 and function covering mappings method; It is characterized in that: said code and control mapping treatment module are used to generate the source code of tested program and the code control mapping table of GUI control; Through in the code analysis to the statement of the definition and the use of GUI control, obtain code control mapping table.
10. code as claimed in claim 6 and function covering mappings method; It is characterized in that: said code covers and the not covering code information of function covering mappings module according to input; Through code control mapping table is searched for; Obtain relevant unlapped graphic user interface GUI list of controls, do not cover code and scan code control mapping table through traversal and generate and do not cover the GUI list of controls.
CN201110295759.3A 2011-09-28 2011-09-28 Code and function covering mapping system and covering mapping method thereof Active CN102436417B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110295759.3A CN102436417B (en) 2011-09-28 2011-09-28 Code and function covering mapping system and covering mapping method thereof

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110295759.3A CN102436417B (en) 2011-09-28 2011-09-28 Code and function covering mapping system and covering mapping method thereof

Publications (2)

Publication Number Publication Date
CN102436417A true CN102436417A (en) 2012-05-02
CN102436417B CN102436417B (en) 2014-08-06

Family

ID=45984492

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110295759.3A Active CN102436417B (en) 2011-09-28 2011-09-28 Code and function covering mapping system and covering mapping method thereof

Country Status (1)

Country Link
CN (1) CN102436417B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102831057A (en) * 2012-08-13 2012-12-19 于秀山 Method for analyzing software function change and influence thereof by using function diagram
CN104657256A (en) * 2013-11-19 2015-05-27 阿里巴巴集团控股有限公司 Method and device for collecting mapping relation between cases and codes
CN106371999A (en) * 2016-10-20 2017-02-01 腾讯科技(深圳)有限公司 Program code testing method and device
CN109977030A (en) * 2019-04-26 2019-07-05 北京信息科技大学 A kind of test method and equipment of depth random forest program

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101436128A (en) * 2007-11-16 2009-05-20 北京邮电大学 Software test case automatic generating method and system
US20100146340A1 (en) * 2008-12-09 2010-06-10 International Business Machines Corporation Analyzing Coverage of Code Changes
CN101916225A (en) * 2010-09-02 2010-12-15 于秀山 Graphical user interface software function coverage testing method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101436128A (en) * 2007-11-16 2009-05-20 北京邮电大学 Software test case automatic generating method and system
US20100146340A1 (en) * 2008-12-09 2010-06-10 International Business Machines Corporation Analyzing Coverage of Code Changes
CN101916225A (en) * 2010-09-02 2010-12-15 于秀山 Graphical user interface software function coverage testing method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
许彤等: "嵌入式处理器在片调试功能的验证", 《计算机辅助设计与图形学学报》 *
隋颖等: "GUI软件测试文档辅助工具的设计与实现", 《计算机技术与发展》 *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102831057A (en) * 2012-08-13 2012-12-19 于秀山 Method for analyzing software function change and influence thereof by using function diagram
CN102831057B (en) * 2012-08-13 2015-02-11 于秀山 Method for analyzing software function change and influence thereof by using function diagram
CN104657256A (en) * 2013-11-19 2015-05-27 阿里巴巴集团控股有限公司 Method and device for collecting mapping relation between cases and codes
CN104657256B (en) * 2013-11-19 2018-07-31 阿里巴巴集团控股有限公司 A kind of method and apparatus for collecting mapping relations between use-case and code
CN106371999A (en) * 2016-10-20 2017-02-01 腾讯科技(深圳)有限公司 Program code testing method and device
CN106371999B (en) * 2016-10-20 2019-08-06 腾讯科技(深圳)有限公司 Program code test method and device
CN109977030A (en) * 2019-04-26 2019-07-05 北京信息科技大学 A kind of test method and equipment of depth random forest program
CN109977030B (en) * 2019-04-26 2022-04-19 北京信息科技大学 Method and device for testing deep random forest program

Also Published As

Publication number Publication date
CN102436417B (en) 2014-08-06

Similar Documents

Publication Publication Date Title
CN102831057B (en) Method for analyzing software function change and influence thereof by using function diagram
EP3745256B1 (en) External code integrations within a computing environment
CN106709356A (en) Static taint analysis and symbolic execution-based Android application vulnerability discovery method
US9747190B2 (en) Analysis system, analysis method, and computer program product
CN102243586B (en) Method for automatically acquiring software function diagram
CN112100054A (en) Data management and control oriented program static analysis method and system
CN108614707A (en) Static code inspection method, device, storage medium and computer equipment
US20180314519A1 (en) Method and apparatus for analyzing impact of software change
CN106557413A (en) Based on the method and apparatus that code coverage obtains test case
CN109508298B (en) Graphical script test method and system
CN109308289A (en) A kind of log parsing template and the log analytic method based on the template
CN104035873A (en) Method and device for generating testing codes
CN102436417B (en) Code and function covering mapping system and covering mapping method thereof
CN103150200A (en) Computer language transformation system and transformation method from C language to MSVL (Modeling, Simulation and Verification Language)
CN103970662B (en) A kind of gui software input border value-acquiring method and system
CN103914379A (en) Automatic fault injection and fault detecting method and system
CN105243018A (en) Object-oriented class test data generation method
CN115270131A (en) Java anti-serialization vulnerability detection method and system
CN108563561B (en) Program implicit constraint extraction method and system
CN106295346A (en) A kind of application leak detection method, device and the equipment of calculating
CN102681932B (en) Method for detecting processing correctness of software on abnormal input
CN103235757B (en) Several apparatus and method that input domain tested object is tested are made based on robotization
CN102087629A (en) Agent embedded software-based invariant test method and tool
Pan et al. Class structure refactoring of object-oriented softwares using community detection in dependency networks
CN109491884A (en) Code method for testing performance, device, computer equipment and medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20230418

Address after: No. 66, Zizhuyuan Road, Haidian District, Beijing 100048

Patentee after: China Software Evaluation Center

Address before: 4101, Building 3, Yard 6, Wanshou Road, Haidian District, Beijing, 100036

Patentee before: Yu Xiushan

TR01 Transfer of patent right