Framework of the week: SwtBot


SwtBot aims to make your Swt (Eclipse) UI testable, it contains many helpers and components to interact with your interface with an automated way.


With SwtBot, you’ll manipulate an instance of ‘bot’ which can interact with the environment. SwtBot uses a Fluent api (each mehotd will return the instance of the bot, allowing you to chain calls.
For example, here’s how to click on the ‘File’-> ‘Save’ menu:"File").menu("Save").click();

Swtbot uses a specific Junit runner to bootstrap the bot at startup. Your test must also extends an SwtBot test class to make the bot available:

public class ClipboardPreferencesTest extends SWTBotEclipseTestCase {
	public void testSave() {"File").menu("Save").click();}

There are multiple test case abstract classes you can extend: SWTBotEclipseTestCase (Swt tests), AbstractViewpointSwtBotGefTestCase (Sirius specific), SwtBotGeftestCase (for Gef/GMF editors tests).

Getting started

In order to begin, you’ve to install SwtBot in your eclipse (update site).
Then, adding all the SwtBot plugins on your run configuration (you can for example import all *swtbot* plugins in your workspace before running the platform you want to test).

Then, you’ll have to create an SwtBot test plugin: a simple Eclipse plugin
containing these Manifest entries:


You can now create a simple test as specified below.

Finnally you can launch an SwtBot Test run configuration and check that your code is correct!

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.