XSLT Unit Testing
Scope
I have been looking for a way to unit test XSLT mappings for a while. Among what I found :
- OxygenXML : I found some article, but the tool requires license and the unit testing is based on other frameworks. CI/CD Integration was not looking possible.
- Altova XMLSpy : Amazing Tool but expensive. I used it in an previous company, years ago but the license fees are really expensive. I was not sure the tests could be used in an automated CI/CD context.
- VSCode : I have found an extension that looked promising : (XSLT XPath extension by DeltaXML)[https://deltaxml.github.io/vscode-xslt-xpath/run-xslt.html]. I did not test it, the configuration looked a bit cumbersome and I don’t think it would have worked out of VS Code.
- XSpec Framework (Git Hub Repo)[https://github.com/xspec/xspec], (Small review on Xml.com)[https://www.xml.com/articles/2017/03/15/what-xspec/] This looked really the extension I was looking for. But after several tries, I was not able to make it run (This is based on Java and Saxon and I am not used to those technologies. If you are used to those technologies you should try.). The framework is also able to generate a report in
- Tennison Test framework : (Tennison Unit Test)[http://tennison-tests.sourceforge.net/index.html]. This was similar to XSpec but the installation process looked easier.
Tennison installation
- Install Java SDK
- Install Saxon Framework The Open Source Package is Saxon-HE. Download : (SourceForge)[https://www.saxonica.com/download/java.xml] Add the path to the jar to the environment variable CLASSPATH
- Download Tennison ressources :
(Sourceforge)[https://sourceforge.net/projects/tennison-tests/files/tennison-tests/Ant%20task/]
There are 2 packages available :
- ant-xslttest-1.0.0-src.zip : Sample files and xslt scripts
- ant-xslttest-1.0.0.zip : java packages The most important is the first one, it contains the scripts to run the tests. The second contains documentation and samples for tests using Java or XSL.
Tennison Scripts corrections
My first tests where not successfull. I had to make some corrections to the scripts.
Updates in the script “Test.bat” :
- In the first block of set commands, I had to replace strange characters with proper paths.
- In the java commands, the charaqcter “.” was missing after the “-o” for the 3 commands.
|
|
Updates in the script “generate-tests-utils.xsl” at the bottom of the script, I replaced the namespace prefix xdt: with xs: (in the 2 occurences of xs:anyAtomicType)
|
|
Once I did those 2 corrections I was able to create test and process them.
Testing xsl
Sample File :
|
|