SWTBot/Ant

From Eclipsepedia

Jump to: navigation, search


SWTBot
Website
Download
Dev Builds
Update Site Ganymede e3.4 Galileo e3.5
Community
Mailing ListNewsgroupIRC
Bugzilla
Open
Help Wanted
Bug Day
Contributing
Contributing


Contents

Executing SWTBot Tests from Ant

SWTBot allows for tests to be executed from ant. Here are some steps that you need to perform in order to run tests in a 'headless' way.

A Screencast

Videos speak louder than pictures and words put together:

Pre-requisites

  • 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

Setup

Your folder structure should look like the following:

ECLIPSE_HOME
 + plugins
  | - com.yourplugins
  | - ...
  | - ...
  | - org.eclipse.swtbot.swt.finder
  | - org.eclipse.swtbot.eclipse.finder
  | - org.hamcrest (and other dependencies)
  | - ...
  | - ...
  | - org.eclipse.swtbot.ant.optional.junit4 (or junit3, but not both) (from the Headless Testing Framework)
  | - org.eclipse.swtbot.eclipse.junit4.headless (or junit3.headless, but not both) (from the Headless Testing Framework)
 + features

Executing

Here's a command line argument that's used to execute the tests:


$ ECLIPSE_HOME=/path/to/your/application
$ TEST_CLASS=com.yourcompany.AllTessts # see http://github.com/ketan/swtbot/blob/master/org.eclipse.swtbot.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/AllTests.java for an example

$ $JAVA_HOME/bin/java \
 -Xms128M -Xmx368M -XX:MaxPermSize=256M \
 -DPLUGIN_PATH= \
 -classpath $ECLIPSE_HOME/plugins/org.eclipse.equinox.launcher_1.0.200.v20090128-1500.jar \
 org.eclipse.core.launcher.Main \
 -application org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication \
 [-testApplication applicationId | |-testProduct productId] \
 -data workspace \
 formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,$ECLIPSE_HOME/$TEST_CLASS.xml \
 formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter \
 -testPluginName org.eclipse.swtbot.eclipse.finder.test \
 -className $TEST_CLASS \
 -os macosx -ws carbon -arch x86 \
 -consoleLog -debug

This will run the test specified by TEST_CLASS and generate the test output in ECLIPSE_HOME/TEST_CLASS.xml. This output can be parsed using junitreport ant task.

Pre-prepared ant tasks

The script at http://github.com/ketan/swtbot/blob/master/org.eclipse.swtbot.releng/test-sandbox/org.eclipse.swtbot.eclipse.finder.test.xml shows an example of how you can use the standard ant task available with SWTBot:

   <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="classname" value="org.eclipse.swtbot.eclipse.finder.AllTests" />
       <property name="vmargs" value=" -Xms128M -Xmx368M -XX:MaxPermSize=256M ${jvmOption}" />
   </ant>

The ${library-file} is part of the Headless Test Framework and can be viewed at http://github.com/ketan/swtbot/blob/master/org.eclipse.swtbot.eclipse.junit4.headless/library.xml. This ant script performs the actual launch for the tests using the command line above.