Eclipse Jubula Automated Test Ant File

As a followup to my previous post on automating Eclipse Jubula tests with Jenkins, here’s an Ant file that

  • Extracts the target platform (Eclipse in this case) and Jubula’s instrumentation plugin
  • Deploys the plugins under test into the target platform (simple copy in this case, no p2 installation)
  • Runs the Jubula tests usingtestexec
  • Collects links to all test results in an index.html file that can be published using the Jenkins HTML Publisher plugin


Prolog

<project name="plugin-test" default="run">
	<!-- Locations -->
	<property name="testdata.dir" value="testdata" />
	<property name="report.dir" value="report/jubula"/>
	<property name="application.dir" value="/tmp/plugin-test/runtime"/>
	<property name="workspace.dir" value="/home/jenkins/.jubula/workspace"/>
	<property name="artifact.dir" value="target"/><!-- Location of plugins under test -->
	<property name="testexec" value="/home/jenkins/jubula/jubula/testexec"/>

	<!-- Derived properties -->
	<property name="deploy.dir" value="${application.dir}/eclipse/plugins"/>
	<property name="report.index" value="${report.dir}/index.html"/>

	<!-- Taskdefs -->
	<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="lib/ant-contrib.jar"/>

	<!-- Main target -->
	<target name="run" depends="check, setup, prepare-runtime, deploy, test, report" />

	<target name="check" unless="application.archive" description="Check configuration">
		<fail message="The mandatory property application.archive pointing to a zipped Eclipse runtime is missing"/>
	</target>

	<target name="setup" description="Prepare directories">
		<delete dir="${report.dir}"/>
		<mkdir dir="${report.dir}"/>
		<delete dir="${testdata.dir}"/>
		<mkdir dir="${testdata.dir}"/>
		<delete dir="${application.dir}"/>
		<mkdir dir="${application.dir}"/>
		<mkdir dir="${artifact.dir}"/>
	</target>

Unpack the target runtime, copy instrumentation plugin and deploy plugins under test

	<target name="prepare-runtime" description="Unpack the runtime application to a working directory">
		<!-- Extract Eclipse -->
		<unzip dest="${application.dir}" src="${application.archive}" overwrite="true"/>
		<chmod perm="a+x" file="${application.dir}/eclipse/eclipse"/>
		
		<!-- Extract Jubula instrumentation plugin -->
		<unzip dest="${application.dir}/eclipse" src="${jubula.plugin.archive}" overwrite="true"/>
	</target>

	<target name="deploy" description="Copy all plugins (target/*.jar) directory to the runtime application's plugins directory">
		<copy todir="${deploy.dir}">
			<fileset dir="${artifact.dir}" includes="*.jar"/>
		</copy>
	</target>

Run Jubula tests using testexec

	<target name="test" description="Run the tests using testexec against an autagent">
		<property name="test.project" value="_your project name_"/>
		<property name="test.project.version" value="1.0"/>
		<property name="test.suite" value="_your test suite name_"/>
		<property name="test.aut.config" value="Eclipse_Helios"/>
		<property name="autagent.host" value="localhost"/>
		<property name="autagent.port" value="60000"/>
		<property name="db.scheme" value="_your DB scheme_"/>
		<property name="db.user" value="_your DB user_"/>
		<property name="db.pwd" value="_your DB pwd_"/>

		<exec executable="${testexec}" failonerror="true">
			<arg line='-project ${test.project} -version ${test.project.version} -testsuite ${test.suite}'/>
			<arg line='-server ${autagent.host} -port ${autagent.port} -autconfig ${test.aut.config}'/>
			<arg line='-datadir "${testdata.dir}" -resultdir "${report.dir}"'/>
			<arg line='-data "${workspace.dir}"'/>
			<arg line='-language en_US -dbscheme "${db.scheme}"'/>
			<arg line="-dbuser ${db.user} -dbpw ${db.pwd}"/>
		</exec>
	</target>

Generate index page with links to test results

	<target name="report" description="Create report index HTML page">
		<!-- Find report files -->
		<fileset id="html.fileset" dir="${report.dir}">
		    <include name="*.htm*" />
			<exclude name="index.html"/>
		</fileset>

		<pathconvert pathsep=";" property="html.filelist" refid="html.fileset">
		    <mapper type="flatten" />
		</pathconvert>

		<!-- Create index page header -->
		<echo file="${report.index}">
			&lt;html&gt;&lt;body&gt;&lt;ul&gt;
		</echo>

		<!-- Add links to all files -->
		<foreach list="${html.filelist}" delimiter=";" target="-print-report-link" param="report.file.name"/>

		<!-- Footer -->
		<echo file="${report.index}" append="true">
			&lt;/ul&gt;&lt;/body&gt;&lt;html&gt;
		</echo>
	</target>

	<target name="-print-report-link" description="Print a link to a Jubula report file into the index page">
		<!-- Strip file prefix -->
		<propertyregex input="${report.file.name}" property="report.file.title" regexp="executionLog-" replace=""/>
		<!-- Create file link in list -->
		<echo file="${report.index}" append="true" message="&lt;li&gt;  &lt;a href=${report.file.name}&gt; ${report.file.title}  &lt;/a&gt;  &lt;/li&gt;"/>
	</target>

</project>
About these ads
This entry was posted in Eclipse, Java, Jenkins, Testing. Bookmark the permalink.

4 Responses to Eclipse Jubula Automated Test Ant File

  1. Pingback: Automating Eclipse Jubula Tests with Jenkins | Development Notes

  2. Alex says:

    Hi Matt,

    I´m currently trying to write a ANT-script, that just automatically runs a test suite. I did it in the console via the “testexec”-command. When I use ANt, I always get an Error, that the database drivers are missing.

    [exec] Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
    [exec] Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:h2:~/.jubula/database/embedded;MVCC=TRUE;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
    [exec] Error Code: 0
    [exec] at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
    [exec] at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
    [exec] at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
    [exec] at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    [exec] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:592)
    [exec] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
    [exec] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:394)
    [exec] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
    [exec] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:242)
    [exec] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:230)
    [exec] at org.eclipse.jubula.client.core.persistence.Hibernator.buildSessionFactoryWithLoginData(Hibernator.java:283)
    [exec] at org.eclipse.jubula.client.core.persistence.Hibernator.(Hibernator.java:159)
    [exec] at org.eclipse.jubula.client.core.persistence.Hibernator.instance(Hibernator.java:591)
    [exec] at org.eclipse.jubula.client.core.persistence.Hibernator.access$4(Hibernator.java:586)
    [exec] at org.eclipse.jubula.client.core.persistence.Hibernator$2.run(Hibernator.java:194)
    [exec] at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
    [exec] Caused by: java.sql.SQLException: No suitable driver found for jdbc:h2:~/.jubula/database/embedded;MVCC=TRUE;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
    [exec] at java.sql.DriverManager.getConnection(Unknown Source)
    [exec] at java.sql.DriverManager.getConnection(Unknown Source)
    [exec] at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:98)
    [exec] … 13 more
    [exec] !!Error occurred !!

    Maybe you also got into this error? Or do you have some hints??

    Thanks!!

  3. Turic says:

    Hi Alex,
    i also get the same error as you described. Did it work now? Do you have any idea about what the problem is and how i can solve it?

    Thanks!

    • Alex says:

      Hi Turic,

      I´m sorry, but I wasn´t able to solve this error in acceptable time. So what I did was, to make a nightly build, using the a shell script to start the tests.

      Greets
      Alex

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s