Another common problem in defining test cases is the labor required to write the test cases and identifying the event sequences that are required to mimic complex use cases. jfcUnit provides the JFCEventManager API's to help reduce the burden with this issue. In 2.0 XML tags are provided for "record" and "save"
The JFCEventManager is a collation engine which collates and filters AWT Events into jfcUnit event data structures. The event manager plugs into the AWTEventQueue as a listener. From the event queue it correlates the AWT events sent via a user direct keyboard / mouse entry or events submitted by jfcUnit's TestHelper methods back into jfcUnits event data structures. These data structures are then passed listeners registered with the JFCEventManager.
Another handy feature of the JFCEventManager is that it can report the events flowing through the AWT Event queue. This can give the test developer some insight into what is happening in the GUI when a particular use case is executed.
Recording via XML
Recording via XML is simple to use. It involves adding a <record/> and <save ...> tags into an XML file. The test cases will execute until the record element is hit. Then the developer may record the new inputs. The inputs will be placed before the record element. The recording will continue until a CTRL-D is presses. After the CTRL-D is hit, the playback of the script will continue until another record tag or the save tag . The <save.../> tag can then be used to write out the new XML file. See JFCUnit via XML.
Turning on debugging
Enabling debugging is a simple process. The following code illustrates how to turn on debugging. This will list the reconstructed jfcUnit event data structures to stdout.
JFCEventManager.setDebug(true); JFCEventManager.setDebugType(JFCEventManager.DEBUG_OUTPUT); JFCEventManager.setRecording(true); Sample Output: JFCEventManager.outputEvent:junit.extensions.jfcunit.eventdata.JTabbedPaneMouseEventData testCase: null modifiers: 16 sleepTime: 0 position:center refPoint: null screenLoc: java.awt.Point[x=179,y=88] component: javax.swing.JTabbedPane[,0,23,782x500,layout=javax.swing.plaf.metal.MetalTabbedPaneUI$TabbedPaneLayout,alignmentX=null,alignmentY=null,border=,flags=1936,maximumSize=,minimumSize=,preferredSize=,haveRegistered=false,tabPlacement=TOP] clicks: 1 popup: false title: Plain Text index: 0 JFCEventManager.outputEvent:junit.extensions.jfcunit.eventdata.JTextComponentMouseEventData testCase: null modifiers: 16 sleepTime: 0 position:center refPoint: null screenLoc: java.awt.Point[x=216,y=207] component: javax.swing.JTextArea[,0,0,555x351,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@307c44,flags=1200,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=153,g=153,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=204,g=204,b=255],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false] clicks: 1 popup: false offset: 0 JFCEventManager.outputEvent:junit.extensions.jfcunit.eventdata.JTextComponentMouseEventData testCase: null modifiers: 16 sleepTime: 0 position:center refPoint: null screenLoc: java.awt.Point[x=225,y=207] component: javax.swing.JTextArea[,0,0,555x351,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@307c44,flags=1200,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=153,g=153,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=204,g=204,b=255],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false] clicks: 1 popup: false offset: 1 JFCEventManager.outputEvent:junit.extensions.jfcunit.eventdata.JTextComponentMouseEventData testCase: null modifiers: 16 sleepTime: 0 position:center refPoint: null screenLoc: java.awt.Point[x=232,y=207] component: javax.swing.JTextArea[,0,0,555x351,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@307c44,flags=1200,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=153,g=153,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=204,g=204,b=255],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false] clicks: 1 popup: false offset: 2 JFCEventManager.outputEvent:junit.extensions.jfcunit.eventdata.JTextComponentMouseEventData testCase: null modifiers: 16 sleepTime: 0 position:center refPoint: null screenLoc: java.awt.Point[x=239,y=207] component: javax.swing.JTextArea[,0,0,555x351,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@307c44,flags=1200,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=153,g=153,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=204,g=204,b=255],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false] clicks: 1 popup: false offset: 3 JFCEventManager.outputEvent:junit.extensions.jfcunit.eventdata.JTextComponentMouseEventData testCase: null modifiers: 16 sleepTime: 0 position:center refPoint: null screenLoc: java.awt.Point[x=242,y=207] component: javax.swing.JTextArea[,0,0,555x351,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@307c44,flags=1200,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=153,g=153,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=204,g=204,b=255],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false] clicks: 1 popup: false offset: 4 JFCEventManager.outputEvent:StringEventData: on javax.swing.JTextArea[,0,0,555x351,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@307c44,flags=1200,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=153,g=153,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=204,g=204,b=255],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false] 0 0 JFCEventManager.outputEvent:StringEventData:This is the text I wanted to enter. on javax.swing.JTextArea[,0,0,555x351,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@307c44,flags=1200,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=153,g=153,b=153],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=204,g=204,b=255],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false] 0 0 JFCEventManager.outputEvent:junit.extensions.jfcunit.eventdata.MouseEventData testCase: null modifiers: 16 sleepTime: 0 position:center refPoint: null screenLoc: java.awt.Point[x=24,y=59] component: javax.swing.JMenu[,0,1,31x21,alignmentX=null,alignmentY=null,border=javax.swing.plaf.metal.MetalBorders$MenuItemBorder@52883b,flags=1568,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=2,bottom=2,right=2],paintBorder=true,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=File] clicks: 1 popup: false |
The input AWTEvents may also be captured by using DEBUG_INPUT or DEBUG_ALL, but these can overwhelm the developer in the details of the events.
Another debug level DEBUG_CREATE shows how the JFCEventManager goes about evaluating which event data to create. This debug level is mainly used when creating new event types.
Turning Off Debugging
Debugging can be turned off with the following method. If the JFCEventManager is not being used to listen to events, be sure to turn off the recording as well. The recording can add a significant overhead to the processing of alarms.
JFCEventManager.setDebug(false); JFCEvnetManager.setRecording(false); |
Listening for Events
Creating a listener for the JFCEventData is illustrated by the following code. Currently, there is no classes which serialize the data into files for editing. (However, a XML version is in the plan for a future release.).
JFCEventManager.getEventManager().addJFCEventDataListener( new JFCEventDataListener() { public void handleEvent(AbstractEventData data) { System.err.println(data); } }); |