Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SWTBot/Ant"

m (Command-line)
m (updated the ant example)
Line 87: Line 87:
 
</fileset>
 
</fileset>
 
</classpath>
 
</classpath>
 +
<jvmarg line="-Xms256M -Xmx768M -XX:MaxPermSize=512M"/>
 
<arg line="-application org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication"/>
 
<arg line="-application org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication"/>
<arg line="-testApplication [my.test.application]"/>
+
<arg line="ARGUMENTS"/>
<arg line="-testPluginName [my.test.plugin]"/>
+
<arg line="FROM"/>
<arg line="-testApplication [my.test.application]"/>
+
<arg line="COMMAND LINE"/>
<arg line="-className [my.swtbot.TestSuite]"/>
+
<arg line="EXAMPLE ABOVE"/>
<arg line="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,junit-results.xml"/>
+
<arg line="-consoleLog"/>
+
<jvmarg line="-Xms40m -Xmx348m -XX:MaxPermSize=512m"/>
+
 
</java>
 
</java>
 
</source>
 
</source>

Revision as of 10:15, 9 August 2010


SWTBot
Website
Update Sites
Community
Mailing List
Forums/Newsgroups
IRC
Contribute
Open Bugzilla tickets
Open Gerrit reviews
Browse Source
Continuous Integration


Automate your SWTBot tests

SWTBot allows for tests to be executed from ant or command-line. 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)
  | - org.junit4 (or org.junit, but not both)
 + features

Executing

Command-line

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


$ ECLIPSE_HOME=/path/to/your/application
$ TEST_CLASS=com.yourcompany.product.test.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
$ TEST_APPLICATION_ID=com.yourcompany.example.application # the id of the application that needs to be tested
$ WORKSPACE=/path/to/your/workspace
$ TEST_PRODUCT_ID=com.yourcompany.product # optional, if you're not using a product, please do not add the -product argument in the command below
$ TEST_PLUGIN_ID=com.yourcompany.product.test # the id of the plugin containing SWTBot tests

$ OS=[macosx | win32 | linux]
$ WS=[[cocoa|carbon] | gtk | win32] # for macosx, linux, and windows respectively.
$ ARCH=[x86|x86_64] # for 32 bit and 64 bit swt binaries.

$ $JAVA_HOME/bin/java \
 -Xms256M -Xmx768M -XX:MaxPermSize=512M \
 -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 $TEST_APPLICATION_ID
 -product $TEST_PRODUCT_ID \ # optional, only if you're working with a product
 -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 $TEST_PLUGIN_ID \
 -className $TEST_CLASS \
 -os $OS -ws $WS -arch $ARCH \
 -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.

Ant

<echo>SWTBot test</echo>
<java dir="${eclipse.home}" fork="true" output="${eclipse.test.home}/output.txt" logError="true" classname="org.eclipse.core.launcher.Main" failonerror="false">
	<classpath>
		<fileset dir="${eclipse.home}/plugins">
			<include name="org.eclipse.equinox.launcher_*.jar"/>
		</fileset>
	</classpath>
	<jvmarg line="-Xms256M -Xmx768M -XX:MaxPermSize=512M"/>
	<arg line="-application org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication"/>
	<arg line="ARGUMENTS"/>
	<arg line="FROM"/>
	<arg line="COMMAND LINE"/>
	<arg line="EXAMPLE ABOVE"/>
</java>
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.

Back to the top