wiki:TestingXSLT/TennisonTests

tennison-tests

The tennison-tests project on SourceForge marries Jeni Tennison’s unit testing stylesheets with an Ant task for running one or more unit test files and producing reports. This framework is most likely to be useful to someone used to using Ant and already using it for unit testing non-XSLT code. As the tennison-tests web page puts it:

The Tennison Tests (XSLT Unit Testing) project aims to harvest the best of both worlds, allowing XSLT Developer's to write their tests in XML and appease the nUnit camp by providing an easy integration into automated build tools, specifically Ant.

Using tennison-tests requires adding the task’s definition and then using it in an Ant target, for example:

<!-- ============================================================= -->
<!-- Targets for running unit tests                                -->
<!-- ============================================================= -->

  <!-- Defines the 'tennison-tests' custom Ant task. -->
  <taskdef name="xslttest"
	   classname="com.jenitennison.xslt.unittest.XSLTTest"
	   classpath="${basedir}/ant-xslttest-1.0.0/ant-xslttest-1.0.0.jar"/>

  <!-- Executes all unit tests in 'test'. -->
  <target name="test" depends="init">
    <xslttest src="${basedir}/ant-xslttest-1.0.0/main/src/xslt"
	      target="build/test"
	      generate="true">
      <fileset dir="${basedir}/test">
	<include name="*.xml" />
      </fileset>
      <factory name="net.sf.saxon.TransformerFactoryImpl"/>
    </xslttest>
  </target>

  <!-- Executes a single unit test. -->
  <!-- Example usage:
          ant -Dtest=2-6.xml test.single
  -->
  <target name="test.single" depends="init">
    <xslttest src="${basedir}/ant-xslttest-1.0.0/main/src/xslt"
	      target="build/test"
	      generate="true">
      <fileset dir="${basedir}/test">
	<include name="${test}" />
      </fileset>
      <factory name="net.sf.saxon.TransformerFactoryImpl"/>
    </xslttest>
  </target>

The generated reports appear identical to those produced by Jeni’s original stylesheets (apart from using a different colour scheme). While the Ant task can run multiple unit test files on one invocation, as yet it does not produce a summary report of all the individual unit test file’s results.