Tycho tests can be run in SWTBot as normal surefire test. The only difference is SWTBot requires '''<useUIHarness>true</useUIHarness>''' and '''<useUIThread>false</useUIThread>'''

+

Tycho tests can be run in SWTBot as normal surefire test. First. you need to make sure SWTBot bundles are available in your [[Tycho/Target Platform#Target platform configuration|target platform]]. Then, the only difference is SWTBot requires '''<useUIHarness>true</useUIHarness>''' and '''<useUIThread>false</useUIThread>'''

Environment requirements

On Mac and Windows, you can only run SWTBot tests in the main UI session, and you have to wait for tests to finish before you can keep on working.
On Linux, you need to have a X session started with a Window Manager. GTK must be installed.

Locally

Linux hints

use another DISPLAY to save time

SWTBot requires tested application to have focus in order to work well. If it happens on the DISPLAY you're working on, then you have to wait for tests to end before you can go on working. It's a waste of time. On Linux, you can run your test on another DISPLAY, so you can keep on working while tests are running. You can use Xephyr for that, since it allows you to see what is happening in another window. You'll also need to have a Window Manager started on this Xephyr. we recommand to run metacity.

The DISPLAY can be set from Eclipse Run configuration, in the Environment tab.

Windows hints

Use Cygwin/X

Never tested...

On Jenkins

Linux hints

Use Xvnc or Xvfb Jenkins plugin in you job to start on X session on a new DISPLAY.

Invoke a "Shell build step" to start a window manager: metacity is recommended, some other may work too, but the oldest ones (such as twm) are known to make some tests failing

Windows hints

Do Not install Jenkins as a service: it causes focus issues that prevent SWTBot from working well.

With Maven and Tycho

Tycho tests can be run in SWTBot as normal surefire test. First. you need to make sure SWTBot bundles are available in your target platform. Then, the only difference is SWTBot requires <useUIHarness>true</useUIHarness> and <useUIThread>false</useUIThread>

A Screencast

Installing headless Testing Framework

If you're using PDE/Build, those bundles must be installed in your target-platform. If you don't use a target-platform definition, then it has to be installed in the Eclipse which hosts your PDE/Build using the following instructions.

If you're trying to run tests on an existing application, you'll need to install SWTBot stuff directly in the application (from installer UI or using the following instructions

With p2 (recommanded)

From your favourite RCP application using p2, run, by replacing SWTBot site by the SWTBot update site of the version you want to use

or unzipping manually (deprecated)

This approach is deprecated because installing bundles just by unzipping does not ensure a successful installation. Using p2 is much better as it will generally work, and if it does not, it tells you why. Please also note that this approach is not supported/tested since SWTBot 2.1.0.

Download the Headless Testing Framework for running tests from within ant. This file is called named something like org.eclipse.swtbot.eclipse.test-2.0.0.187-dev.zip

You'll need the following plugins from swtbot (you don't need all the swtbot packages)

org.eclipse.swtbot.swt.finder

org.eclipse.swtbot.eclipse.finder

org.hamcrest

org.junit4(recommended) you may also use org.junit

org.apache.log4j

Installing your p2 test plugin

If you're using PDE/Build, then your test bundle needs to be either available in the workspace then built and installed at the same time as your other bundle, or installed in the target-platform.

If you're trying to run tests on an existing application, you'll need to install SWTBot stuff directly in the application (from installer UI or using the following instructions. This can be achieved using the p2.director cammand-line or Ant task.

Executing

The key is to run the org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication

Debugging from Eclipse

You can enable debug using standard JVM debug flags on your test process -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y and then using Eclipse debug "Remote Java Application", bind it to port 8000 (as specified by socket in command-line).

On an already packaged RCP application

Alter an RCP application to install and run your tests

Your tests must be available in a p2 repository/update-site

Use p2 UI or p2 director in install SWTBot + your test bundles from update-sites into you application

Use the command-line described earlier to start SWTBot test execution on your application (think about setting the -product and/or -application parameters)

You can debug this from Eclipse using the command-line arguments described earlier.

Or, use your IDE to run tests on an existing application

Install SWTBot in your IDE to access the SWTBot configuration menus

Create a Target Platform made of your application + SWTBot runtime.

Import your test bundles as projects in your workspace

Then use the "SWTBot tests" wizard to configure the execution: think about including all Target Platform + SWTBot + your tests bundles; and configure product to refer to your application.