My Two Cents

July 31, 2009

SWTBot for Eclipse UI Testing

Filed under: Eclipse,Java,Software — zuma @ 8:20 pm
After reviewing several tools for writing UI tests for Eclipse based products, I finally settled down on SWTBot. Testing UI code is not an easy undertaking, in general. What drove me towards SWTBot was the simplicity in writing tests, and also their ongoing effort in providing support for GEF (Graphical Editing Framework). Not to say that other tools do not provide nice features. I have heard that Window Tester from Instantiations is also good and provide good support. But SWTBot provided the quick start I needed to get some tests writting for the UI (ofcourse EPL license helps! :) ).

SWTBot was not part of the Galileo release train, but you can still use their plugins with Galileo (and that still qualifies my article for the Eclipse Blogathon (http://www.eclipse.org/galileo/blogathon/guidelines.php), I hope!). SWTBot is still an incubation project, and their support for GEF is currently hosted under Google Code. But even at this early stage, SWTBot is quite functional, and shows promise for becoming a robust test tool for Eclipse plugin and RCP developers.
SWTBot is launched similar to how a JUnit Plugin test is launched, except that an SWTBot launch runs in a non-UI thread. SWTBot also provides options to run in a headless mode, and an ant task to integrate for continuous testing. Writing test code with SWTBot is simple enough. The following code snippet opens the Import dialog to import projects into a workspace.
workbenchBot.menu(“File”).menu(“Import…”).click();
workbenchBot.tree().select(“General”).expandNode(“General”).select(“Existing Projects into Workspace”);
As you can see, the code is very readable and relatively easy to write. SWTBot lacks a Recorder (apparently there is one, but it is not actively maintained). In my opinion, a Recorder is useful only initially to get the hang of things, but once you start writing reusuable test modules, a Recorder loses much of its value. So I do not see it to be a big disadvantage, though having a recorder wouldn’t hurt.
If you are interested in trying out SWTBot, here are some resources to get you started:
SWTBot: http://www.eclipse.org/swtbot/
Eclipse UI Test Tools Comparison: http://wiki.eclipse.org/Automated_Testing#UI_tests
SWTBot for GEF: http://code.google.com/p/swtbot4gef/

After reviewing several tools for writing UI tests for Eclipse based products, I finally settled down on SWTBot. Even after being a long time Eclipse plugin developer, I always found that I lacked a good tool for testing UI. I kept as much business logic code as possible away from UI code and wrote regular JUnit tests for that. But invariably, I ended up in situations where it made a lot of sense to write UI tests. What drove me towards SWTBot was the simplicity in writing tests, and also their ongoing effort in providing support for GEF (Graphical Editing Framework). Not to say that other tools do not provide nice features. I have heard that Window Tester from Instantiations is also good and provide good support. But SWTBot provided the quick start I needed to get some tests writting for the UI (ofcourse being an Eclipse project, and having an EPL license helps! :) ).

SWTBot is not part of the Galileo release train, but you can still use their plugins with Galileo (and that still qualifies my article for Eclipse Blogathon, I hope!). SWTBot is still an incubation project, and their support for GEF is currently hosted under Google Code. But even at this early stage, SWTBot is quite functional, and shows promise for becoming a robust test tool for Eclipse plugin and RCP developers.

SWTBot is launched similar to how a JUnit Plugin test is launched, except that an SWTBot launch runs in a non-UI thread. SWTBot also provides options to run in a headless mode, and an ant task to integrate for continuous testing. Writing test code with SWTBot is simple enough. The following code snippet opens the Import dialog to import projects into a workspace.

workbenchBot.menu(“File”).menu(“Import…”).click();

workbenchBot.tree().select(“General”).expandNode(“General”).select(“Existing Projects into Workspace”);

As you can see, the code is very readable and relatively easy to write. SWTBot lacks a Recorder (apparently there is one, but it is not actively maintained). In my opinion, a Recorder is useful only initially to get the hang of things, but once you start writing reusuable test modules, a Recorder loses much of its value. So I do not see it to be a big disadvantage, though having a recorder wouldn’t hurt.

If you are interested in trying out SWTBot, here are some resources to get you started:

SWTBot: http://www.eclipse.org/swtbot/

Eclipse UI Test Tools Comparison: http://wiki.eclipse.org/Automated_Testing#UI_tests

SWTBot for GEF: http://code.google.com/p/swtbot4gef/

2 Comments »

  1. Hi, I’m a new user for any Java Tool. Please let me know from initial point, how to use SWT from eclipse download.

    Comment by Arvind — November 16, 2009 @ 9:19 pm

  2. Do you recommend such kind of tool for beginners like me? A recorder is sure beneficial to me.

    Comment by Chess Franklin — April 17, 2011 @ 8:31 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress