Run Twist Scenarios from Ant
Twist scenarios can be executed from within Ant. This makes Twist
Continuous Integration
friendly, and allows your tests to be run as part of
a build within tools such as Cruise
.
Export Twist Libraries
Using Ant Integration
Twist provides an Ant task which enables you to run your Scenarios as part of the build.
The Twist Ant task accepts all attributes that are accepted by the Java Ant task. The task additionally supports 'scenarioDir' and 'tags' attributes. The 'tags' attribute accepts comma separated tags.
You can add multiple targets with different set of tags, and use normal Ant conditional logic in order to build a build pipeline.
The easiest way for using Twist together with Ant is to first export a build.xml for your project using File > Export > General > Ant Buildfiles. Twist provides additional Content Assist in the Eclipse Ant editor, allowing you to insert a 'twist-target' template.
The following snippet shows the Twist test target added to the Example Mingle Suite shipped with Twist.
<target name="execute-scenarios" description="Executes scenarios">
<path id="scenarios.classpath">
<path refid="${ant.project.name}.classpath" />
<fileset dir="${ant.library.dir}" includes="*.jar" />
</path>
<taskdef
classname="com.thoughtworks.twist.core.execution.ant.ExecuteScenariosTask"
classpathref="scenarios.classpath"
name="twist.runner" />
<property name="test-reports" value="${basedir}/reports/ant-reports" />
<property name="twist-config" value="${basedir}/twist-conf"/>
<delete dir="${test-reports}" />
<mkdir dir="${test-reports}" />
<mkdir dir="${test-reports}/html" />
<twist.runner
scenarioDir="${basedir}/scenarios"
reportsDir="${test-reports}"
confDir="${twist-config}"
failureproperty="twist.scenarios.failed"
classpathref="scenarios.classpath"
tags="!in-progress" />
<fail if="twist.scenarios.failed" message="One or more scenarios failed during execution" />
</target>
The following are the properties provided on the twist-runner Ant task.
| scenarioDir | The path to the directories in the project where the scenario files are stored. |
| reportsDir | Location of the Twist HTML reports. |
| confDir | Location of the Twist configuration files. |
| classpathref | Location of java source files linked to the scenarios. |
Optional properties
| tags | scenarios tagged with these tags will be run a part of the build |
Additionally, the process of including the Twist tests in the Ant build is simplified by providing an Ant template, twist-target which is available as a Content Assist in Ant Editor.
Twist relies on JUnit to do assertions and to provide test reports. Most Continuous Integration tools have good JUnit support. In Cruise Control, the JUnit results will be picked up automatically and shown as part of the build report (HTML Reports).
For detailed information about Ant and how it works, please visit http://ant.apache.org