PR0031 - 2010-11-01 Redistribution and other use of this material requires written permission from The RCP Company. Test UI Aspects of Plug-ins Testing the UI of an Eclipse plug-in is usually considered rather difficult and something that is best left for specialized tools. Also, the test is often considered very fragile and is expected to be updated whenever you make even the smallest change to your UI. But that need not be so. By using a few rather simple tools and a few just as rules, you can test all the UI parts of an application... This presentation was made for Eclipse Summit Europe 2010.
21
Embed
Eclipse Summit Europe '10 - Test UI Aspects of Plug-ins
Testing the UI of an Eclipse plug-in is usually considered rather difficult and something that is best left for specialized tools. Also, the test is often considered very fragile and is expected to be updated whenever you make even the smallest change to your UI. But that need not be so. By using a few rather simple tools and a few just as rules, you can test all the UI parts of an application...
This presentation was made for Eclipse Summit Europe 2010.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
PR0031 - 2010-11-01
Redistribution and other use of this material requires written permission from The RCP Company.
Test UI Aspects of Plug-ins
Testing the UI of an Eclipse plug-in is usually considered rather difficult and something that is best left for specialized tools. Also, the test is often considered very fragile and is expected to be updated whenever you make even the smallest change to your UI.But that need not be so. By using a few rather simple tools and a few just as rules, you can test all the UI parts of an application...
This presentation was made for Eclipse Summit Europe 2010.
PR0029 - 2010-05-31
2
About Me
Tonny Madsen, Founder and Owner of The RCP Company
20 years of experience in system development in major companies 9 years experience as the Systems Architect of an 20+ MLoC project 8 years of experience with Eclipse and Eclipse RCP
Solutions Member of the Eclipse Foundation Chairman of Eclipse.dk Extern Lecturer at IT-University on Model Driven Development and
Domain Specific Languages Regular speaker at EclipseCon, Eclipse Summit, etc
PR0031 - 2010-11-01
3
Downloads
This presentation makes some use of a library of low-level test methods.
One of a large number of methods IWorkbenchPage.findEditor(IFile file) No specific command
Views IWorkbenchPage.showView(String id)
Will open the view in the site according to the perspective definition Command org.eclipse.ui.views.showView
PR0031 - 2010-11-01
9
Testing Interaction
UI tests often have to interact with the application in a manner that is identical or at least similar to the interaction by a user
Several way to interact Directly via generated events – especially mouse and key related events Indirectly via manipulation of SWT widgets Indirectly via commands Indirectly via handlers
Which way to use often depends on the level of knowledge of the application implementation permitted by the tester
In all cases you also need to handle the event loop as tests often runs in the event thread
PR0031 - 2010-11-01
10
Test Interaction – Mouse and Key
A subset of generated mouse and key events can be handled via Display.post(Event)
KeyDown, KeyUp Key down and up must be paired Modifiers must be “pressed” separately Textual descriptions of key strokes can be converted to key codes via KeyStroke.getInstance(stroke)
MouseDown, MouseUp MouseMove
Mouse must be moved before “pressed” Double-click is handled by clicking twice
MouseWheel
PR0031 - 2010-11-01
11
Test Interaction – Mouse and Key
public static void postMouse(Control c, Point p) {final Point pt = c.getDisplay().map(c, null, p);
final Event e = new Event();e.type = SWT.MouseMove;e.x = pt.x;e.y = pt.y;assertTrue(c.getDisplay().post(e));yield();
If the test runs in the event thread, event dispatching can be needed. Required after use of Display.post(Event)
To dispatch all events in the event queue use (often known as yield)
To dispatch all paint requests for a control – possible children
To wait a certain period while dispatching events use
while (display.readAndDispatch()) {}
cont = false;display.timerExec(msec, new Runnable() {
@Overridepublic void run() {
cont = true;}
});while (!cont) {
if (!display.readAndDispatch()) {display.sleep();
}}
control.update();
PR0031 - 2010-11-01
13
Test Interaction – Direct Manipulation of Widgets
A lot of testing can be done by manipulating widgets directly Cons: it requires an intimate knowledge of the application Pros: it is very robust to many types of changes in the application
public class TestView extends ViewPart {public Text myText;
myView.myText.setText("hello");// Testing the result…
}}
PR0031 - 2010-11-01
15
Test Interaction – Direct Manipulation of Widgets
Some often used cases Entering characters into a text widget: Text.setText(str) Selecting item in combo box: Combo.setText(str) or Combo.select(i) Ticking check boxes and radio buttons: Button.setSelection(b)
But not push buttons! Moving scrollbars, sliders, and scales: ScrollBar.setSelection(i) Changing a tab in a tab folder: TabFolder.setSelection(i)
Though no selection event is posted
PR0031 - 2010-11-01
16
Test Interaction – Executing Simple Commands
A simple command has no parameters
IHandlerService hs = …;
hs.executeCommand("<command-id>", null);
PR0031 - 2010-11-01
17
Test Interaction – Executing Parameterized Commands
A parameterized command has one or more parameters and can be created in one of two ways: