Thursday, July 23, 2009

Running Eclipse Plugin Tests with SWTBot in Headless Mode

This is a followup to my previous post on SWTBot. Headless mode is very useful in running tests outsode of eclipse through Ant or from the command line.


Well, it's not exactly headless. A better title would be "running Eclipse Plugin Tests with SWTBot with Ant or From The Command Line." The tests are not run from an Eclipse workbench, but they require Eclipse, and actually open up a workbench when they are run.


Here's the place to start:

Download the "Headless Testing Framework" from here: and install it into your eclipse /plugins dir. You need to install both the junit4.headless and optional.junit4 files. For example:


Important note: Be sure to install only these files for either JUnit3 or JUnit4. If you install the files for both versions of JUnit, you'll see many class cast exceptions.


Be sure to define a class to serve as a test suite for your tests. For example;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@SuiteClasses( { TestPositive.class, TestNegative.class })
public class AllTests {

Export your plugin tests (as a plugin) and install it into the /plugins directory of your eclipse installation.

Running with Ant

Build a build.xml file that looks like this:

<?xml version="1.0" encoding="UTF-8" ?>

<project name="testsuite" default="run" basedir=".">
<property name="eclipse-home" value="/opt/local/eclipse_swtbot/eclipse" />
<property name="plugin-name" value="" />
<property name="test-classname" value="" />
<property name="library-file" value="${eclipse-home}/plugins/org.eclipse.swtbot.eclipse.junit4.headless_2.0.0.371-dev-e34/library.xml" />

<target name="suite">

<property name="jvmOption" value=""></property>
<property name="temp-workspace" value="workspaceJuly23" />
<delete dir="${temp-workspace}" quiet="true" />

<ant target="swtbot-test" antfile="${library-file}" dir="${eclipse-home}">
<property name="data-dir" value="${temp-workspace}" />
<property name="plugin-name" value="${plugin-name}" />
<property name="os" value="linux" />
<property name="ws" value="gtk" />
<property name="arch" value="x86" />
<property name="classname" value="${test-classname}" />
<property name="vmargs" value="-Xms128M -XX:MaxPermSize=512m -Xmx512M" />

<target name="cleanup" />

<target name="run" depends="suite,cleanup">

Important note: The supported values for os, ws (workspace) and arch are:

os: win32/linux/macosx
ws: win32/wpf/gtk/cocoa/carbon
arch: x86/x86_64

Important note: Be sure to specify a non-existent workspace name for temp-workspace as this will be overwritten when the test is run.

Running from the CLI

export ECLIPSE_HOME=/opt/local/eclipse_swtbot/eclipse

java -Xms128M -Xmx368M -XX:MaxPermSize=256M -DPLUGIN_PATH= -classpath $ECLIPSE_HOME/plugins/org.eclipse.equinox.launcher_1.0.101.R34x_v20081125.jar org.eclipse.core.launcher.Main -application org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication -data workspace,$ECLIPSE_HOME/$TEST_CLASS.xml -testPluginName -className $TEST_CLASS -os linux -ws gtk -arch x86 -consoleLog -debug

Test Output

It can be hard to find in all the output, but it's there:

Testcase: checkPerspective took 3.529 sec
Testcase: canConnectToRepo took 5.784 sec
Testcase: goIntoBackHomePropertiesTest took 34.526 sec
Testcase: doubleClickTest took 51.74 sec
Testcase: cannotConnectBadPath took 6.701 sec
Testcase: cannotConnectBadPassword took 7.747 sec

Other Useful Links

Ketan added some movies to the SWTBot site in July 2009. Here's one on running SWTBot from Ant:

Another DZone post!

The recent post on Gateways and Notifiers in the SOA Platform was just reposted to DZone here:

Monday, July 20, 2009

A new post for the SOA Platform blog

Just added a new post here:

Listeners and notifiers are very useful things to integrate apps together through the platform. They are actually easy to use, and are very powerful too!

Thursday, July 9, 2009

Another post to the Red Hat / JBoss SOA Platform Blog

I just finished my 2nd post to the SOA Platform blog here:

The diagram towards the end would have really helped me understand content based routing when I first heard of it. Maybe this will help some other newbies along the way... ;-)