Your SlideShare is downloading. ×
0
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

SwtBot: Unit Testing Made Easy

4,646

Published on

SWTBot is a open source UI testing tool for SWT and Eclipse based applications. It requires bare minimum learning since it is Java based and integrates well with the JUnit framework. …

SWTBot is a open source UI testing tool for SWT and Eclipse based applications. It requires bare minimum learning since it is Java based and integrates well with the JUnit framework.

An ideal unit testing tool for SWT and Eclipse based applications developers.

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
4,646
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
75
Comments
1
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • QTP:Pre-work required – repositoryNot cross platform – runs only on windows – no linux supportEven though its one of the fastest tools in the market – its still slower than SWTBotLearning requiredBetter because multiple types of apps can be supportedSWTBot provides APIs that are simple to read and write.No-hassle tool for writing powerful tests
  • SWTBot provides APIs that are simple to read and write. These APIs hide away the complexities of SWT and Eclipse. This makes it suitable for use by everyone and not just developers.
  • If you scroll down the stack trace in the JUnit view, you’ll see the cause of the error.The@RunWith(SWTBotJunit4ClassRunner.class)annotation captures a screenshot in a screenshots directory in your project. Refresh your project to see the new folder.
  • List of Not Yet Supported SWT WidgetsButton Arrow,Browser,Canvas,Composite,CTabFolder,Link,ProgressBar,Sash,Scale, ScrolledComposite,Slider,Spinner,TabFolderNot Yet Supported UI ToolkitsGEFEclipse FormsNebulaeSWT & eRCPRAP (work in progress)Native Dialogs (MessageBox, FileDialog, ColorDialog etc.)Most of it is planned to be supported them ASAP
  • A demo mapping all the theory learnt so far into a practical example
  • It's generally accepted that writing tests as part of software development is a very good thing indeed. It's also generally accepted that automating the running of tests in an automated or nightly build is good engineering practice. Let's face it, if tests are not run automatically then there's a good chance they won't be run at all, and tests that are not run are next to useless.SWTBot provides an excellent framework to write and run unit tests for your plug-ins that can be run from within the Eclipse environment.Once you have taken the time and effort to write these valuable unit tests, how do you automate the running of these unit tests so that you can integrate them into your automated build?
  • A demo showing how execution on unit tests can be integrated with the regular build system
  • List of Not Yet Supported SWT WidgetsButton Arrow,Browser,Canvas,Composite,CTabFolder,Link,ProgressBar,Sash,Scale, ScrolledComposite,Slider,Spinner,TabFolderNot Yet Supported UI ToolkitsGEFEclipse FormsNebulaeSWT & eRCPRAP (work in progress)Native Dialogs (MessageBox, FileDialog, ColorDialog etc.)Most of it is planned to be supported them ASAP
  • Transcript

    • 1. SWTBot: Unit Testing Made Easy<br />Eclipse Day India 2011<br />Ankit Goel<br />6th May, 2011<br />
    • 2. Agenda<br />PART I – About SWTBot<br />Introduction to SWTBot<br />SWTBot Features<br />Supported Widgets<br />Test Executions<br />PART II - Integrating SWTBot tests execution with continuous build system<br />What more?<br />Limitations<br />
    • 3. PART I – About SWTBot<br />
    • 4. Introduction – What is SWTBot?<br />Java based UI/functional testing tool for testing SWT and Eclipse based applications<br />Set of API’s to access and manipulate widgets<br />Cross platform<br />Free and open source<br />Still in Incubation Phase in Eclipse<br />
    • 5. Introduction – Why SWTBot?<br />Why not QTP? Why not PDE Junit? Why not…<br />Provides an intuitive way to access and test UI components in Eclipse<br />UI Testing covers all layers of software<br />Easy to learn if someone is already familiar with Java and JUnit<br />Can integrate very well within the IDE and provides excellent support for integration with Ant<br />
    • 6. Introduction – Who is it for?<br />Developers<br />Unit tests<br />Integration with build ensures quality builds<br />QA<br />Test automation<br />Quality product<br />
    • 7. Setting up Eclipse environment<br />SWTBot update site<br />http://www.eclipse.org/swtbot/downloads.php<br />Create a plugin project and setup dependencies<br />org.eclipse.ui<br />org.eclipse.core.runtime<br />org.eclipse.swtbot.eclipse.finder<br />org.eclipse.swtbot.junit4_x<br />org.eclipse.swtbot.swt.finder<br />org.junit4<br />org.hamcrest<br />Or, create a SWTBot test plugin<br />
    • 8. How does it work?<br />SWTBot = bot which acts on SWT components<br />Entry point: org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot<br />Helper classes for widgets<br />To test:<br />Instantiate bot<br />SWTWorkbenchBotbot = new SWTWorkbenchBot();<br />Click on button<br />SWTBotButton button = bot.button("Hello, World!“);<br />button.click();<br />Congrats! You have just written your first SWTBOT test <br />
    • 9. SWTBot Features<br />Finding controls based on visual cues<br />Support for simulated mouse and keyboard input<br />Querying widgets for state<br />UI specific assertions like: assertEnabled(Widget)<br />Investigating test failures<br />
    • 10. SWTBot Features – Finding Controls<br />Controls can be found based on visual cues like:<br />Text<br />Label<br />Group<br />Tooltip<br />Ids<br />Combination of all or any of the above (Using matchers)<br />Eg:<br />Find textbox that has a label 'Username:‘<br />SWTBotText username = bot.textWithLabel("Username:"); <br />Identify button using tooltip <br />SWTBotToolbarButton save = bot.toolbarButtonWithTooltip("Save");<br />
    • 11. SWTBot Features – Using matchers<br />Simple matchers<br />withText(“Finish”)<br />withLabel(“Username:”)<br />withRegex(“Proceed to step * ”)<br />widgetOfType(Button.class)<br />withStyle(SWT.ARROW, “SWT.ARROW”)<br />Combination of matchers<br />allOf(matchers)<br />anyOf(matchers)<br />not(matchers)<br />
    • 12. Filtering controls using Matchers<br />Match : widgets of type 'Label' <br /> with regular expression 'Welcome, <USERNAME>' <br />Matcher matcher = allOf( <br />widgetOfType(Label.class), <br />withRegex("Welcome, .*") ); <br />Get the label that matches the matcher <br />SWTBotLabel label = <br /> new SWTBotLabel((Label) bot.widget(matcher));<br />
    • 13. SWTBot Features – Simulate input <br />SWTBot provides API to simulate actions on widgets<br />Eg:<br />Click a button<br />button.click(); <br />Select a item in combobox<br />comboBox.select(“Option 12"); <br />Type in a textbox<br />text.typeText(“This is a demo string"); <br />Expand tree<br />tree.expandNode("MyProject", "src", "com", "example", "MyClass.java");<br />
    • 14. SWTBot Features – Querying widgets<br />Provides operations to query the state of widgets<br />Some generic queries like: getText(), isEnabled(), isVisible() are available on all widgets<br />Eg:<br />Check state of a checkbox<br />booleanchecked = checkbox.isChecked();<br />Check if a radio button is selected<br />boolean selected = radio.isSelected();<br />
    • 15. SWTBot Features – Investigating test failures<br />Stack trace in Junit view<br />Capturing screen shot when test case fails<br />@RunWith(SWTBotJunit4ClassRunner.class)<br />publicclassMessageCreateTest{<br />...<br /> …<br />}<br />
    • 16. Supported Widgets<br />Support for most SWT controls<br />Support for most UI operations on SWT controls<br />Support for Eclipse based contributions:<br />Views<br />Text Editors (autocompletion, typing, etc)<br />View Toolbars and View Menus<br />
    • 17. SWT Test Execution<br />By launching them from launch configuration (same as Junit execution)<br />From command line, using shell script or ant<br />
    • 18. Demo<br />A small SWTBot example illustrating the simplicity of SWTBot<br />Your first SWTBot<br />
    • 19. PART II – Integrating SWTBot tests execution with continuous build system<br />
    • 20. Integration of test execution with continuous build<br />Build plugins to be tested<br />Build SWTBot test plugins<br />Install plugins to be tested, test plugins and headless testing framework (http://www.eclipse.org/swtbot/downloads.php) into eclipse<br />Start SWTBot test case execution<br />Format the generated report and mail if required<br />
    • 21. Pre-requisite<br />Each test plugin must contain test.xml<br />Set appropriate properties<br />Delegate execution of test to a library file<br />Test plugins should always be ‘unpacked’<br />
    • 22. Under the covers…<br />For each test plugin<br />Invoke test.xml which will<br />Set required properties like class name, plugin name, directory to use as temp workspace etc<br />Invoke target ‘swtbot-test’ of library file located in ‘org.eclipse.swtbot.eclipse.junit4.headless’ plugin which will then launch and execute all test cases<br />Invoke target ‘collect’ of library file located in ‘org.eclipse.swtbot.eclipse.junit4.headless’ plugin which will consolidate test case results in one file<br />Format the generated results file (xml file) into desired format (usually html)<br />
    • 23. Snippet – test.xml<br /><anttarget="swtbot-test"antfile="${library-file}"dir="${eclipse-home}"><br /> <property name="data-dir"value="${temp-workspace}" /><br /> <propertyname="plugin-name"value="${plugin-name}" /><br /> <propertyname="classname”value=“${class-name}" /><br /> <propertyname="vmargs"value=" -Xms128M -Xmx368M - XX:MaxPermSize=256M" /><br /></ant><br />
    • 24. Still confused ?<br />This would surely help<br />
    • 25. What more?<br />Parse results file and fail build if any of the test fails – ensuring only quality builds go to QA<br />Code Coverage – write more tests to test uncovered code<br />
    • 26. Limitations<br />Less documentation available<br />Some SWT widgets not supported yet!<br />No support for other UI toolkits – GEF, Nebula etc<br />

    ×