The task allows you to call the tennison-test templates from within Ant, reporting the results as HTML and failing the build if any fail.
The task works only with Saxon and has been tested with saxon-8.7 but may work earlier versions.
To use the Schema Aware version of Saxon (Saxon SA), you will need JAXP 1.3 classes
if you're using Java 1.4 (Java 5.0 users already has it). Download from
https://jaxp.dev.java.net/servlets/ProjectDocumentList, extract the archive
and add jaxp-api.jar
and dom.jar
to
%ANT_HOME%\lib
.
The task is part of the Tennison Tests (XSLT Unit Testing) project (http://tennison-tests.sourceforge.net/) and utlises the set of templates therein. You must therefore store the templates
in a folder before using this task. For convenience, these are included in the
task's JAR file (under main/src/xslt
).
There are also some sample templates in the JAR (under main/test/xslt
).
A later version of the task may be able to load them directly from the archive, but for now, they must be extracted and located externally (however, this does allow you to modify the templates easily, for example changing the report css).
To use, add the following to your Ant script.
<taskdef name="xslttest" classname="com.jenitennison.xslt.unittest.XSLTTest" classpath="ant-xslttest-v1.0.0.jar" />
SNAPSHOT
in the JAR file name would indicate a
snapshot version release, not necessarily
the latest or formal release. The task is available from the project's
home page and is under the GNU LGPL lisense. Its fairly new so feel
free to contribute.
Attribute | Description | Required |
src | the location of the tennison tests; you need to download these and put them here | Yes |
target | the output location. | Yes |
generate | generate the TEST- file. Skips the generate step if false. If false, the TEST- file must be pre-generated | No (default to true) |
licensefolder | the folder where the saxon-license file exists if using Saxon SA | No (uses default) |
The fileset containing the XSLT unit tests, see Jeni Tennison's original pages for instructions on how to write tests.
since Ant 1.6.5.
Attribute | Description | Required |
name | fully qualified classname of the
transformer factory to use (must be TraX compliant). For example
| Yes |
attribute
Used to specify settings of the processor factory. The attribute names and values are entirely processor specific so you must be aware of the implementation to figure them out. Read the documentation of your processor. For example, in Xalan 2.x:
And in Saxon 8.x:
- http://xml.apache.org/xalan/features/optimize (boolean)
- http://xml.apache.org/xalan/features/incremental (boolean)
- ...
Constant Id Feature Type ALLOW_EXTERNAL_FUNCTIONS http://saxon.sf.net/feature/allow-external-functions boolean COLLATION_URI_RESOLVER http://saxon.sf.net/feature/collation-uri-resolver ? COLLECTION_URI_RESOLVER http://saxon.sf.net/feature/collection-uri-resolver ? DTD_VALIDATION http://saxon.sf.net/feature/validation ? LINE_NUMBERING http://saxon.sf.net/feature/linenumbering Integer MESSAGE_EMITTER_CLASS http://saxon.sf.net/feature/messageEmitterClass ? NAME_POOL http://saxon.sf.net/feature/namePool ? OUTPUT_URI_RESOLVER http://saxon.sf.net/feature/outputURIResolver ? RECOGNIZE_URI_QUERY_PARAMETERS http://saxon.sf.net/feature/recognize-uri-query-parameters ? RECOVERY_POLICY http://saxon.sf.net/feature/recoveryPolicy ? SCHEMA_VALIDATION http://saxon.sf.net/feature/schema-validation integer SOURCE_PARSER_CLASS http://saxon.sf.net/feature/sourceParserClass ? STRIP_WHITESPACE http://saxon.sf.net/feature/strip-whitespace ? STYLE_PARSER_CLASS http://saxon.sf.net/feature/styleParserClass ? TIMING http://saxon.sf.net/feature/timing boolean TRACE_EXTERNAL_FUNCTIONS http://saxon.sf.net/feature/trace-external-functions ? TRACE_LISTENER http://saxon.sf.net/feature/traceListener String TREE_MODEL http://saxon.sf.net/feature/treeModel Integer VALIDATION_WARNINGS http://saxon.sf.net/feature/validation-warnings ? VERSION_WARNING http://saxon.sf.net/feature/version-warning ? XML_VERSION http://saxon.sf.bet/feature/xml-version ? Parameters
Attribute Description Required name name of the attribute Yes value value of the attribute. Yes
since Ant 1.6.5.
<xslttest src="main/src/xslt" target="target/output" generate="true"> <fileset dir="main/test/xslt"> <include name="standalone*.xml" /> <include name="*.xsl" /> <exclude name="failing-sample.xsl" /> </fileset> <factory name="net.sf.saxon.TransformerFactoryImpl"/></xslttest>
runs the unit tests main/test/xslt/standalone*.xml
and main/test/xslt/*.xsl
but excluding main/test/xslt/failing-sample.xsl
. The "Tennison tests" templates
are located in the main/src/xslt
folder and the results generated in
the target/output
folder. This uses the Saxon transformation engine.
<xslttest src="main/src/xslt" target="target/output"> <fileset dir="${xslttest}"> <include name="**/standalone*.xml" /> <exclude name="failing-sample.xsl" /> </fileset> <factory name="com.saxonica.SchemaAwareTransformerFactory"> <attribute name="http://saxon.sf.net/feature/allow-external-functions" value="true"/> <attribute name="http://saxon.sf.net/feature/schema-validation" value="2"/> <attribute name="http://saxon.sf.net/feature/validation-warnings" value="true"/> </factory></xslttest>
runs the unit tests as for the previous example (but against main/test/xslt/standalone*.xml
only. Uses the Saxon Schema Aware (SA) parser with some features set. NB: if you're using
the SA parser, you'll need a valid licence file available to the classpath. This can be done with the
following;
set CLASSPATH=%CLASSPATH%;[folder]
where [folder] is the folder where the license file (saxon-license.lic for example) exsists.
or use the licensefolder
attribute.
<xslttest src="main/src/xslt" target="target/output" generate="false"> <fileset dir="${xslttest}"> <include name="TEST-sample.xsl" /> </fileset> <factory name="net.sf.saxon.TransformerFactoryImpl" /></xslttest>
runs the tests defined in the TEST-sample.xsl
file. This file has been
pre-generated, by setting the generate
attribute to false, the task will not
attempt to genereate tests using the generate-tests.xsl
template.
See the writing tests section to understand how to write pre-generated tests.