XML test scripts / runners
Is there any xml testing frameworks out there that would allow me to write scripts for testing/asserting contents of an xml file??
Note: I know that such frameworks exist as extensions for programming language testing frameworks such as Java and .NET.
What I am looking is having something independent of any programming language. I would like to write xml testing scripts in notepad and not have to compile them. (Something like DBFit but for XML). See below for an example of what I am looking for.
<parent> <value name ="bob"/> </parent>
Sample XML Test Script
assert(xpath("/parent/value/@name") == 'bob');
You could roll your own solution fairly easily using XSLT.
Here is an example of an XSLT that evaluates your assertion criteria and if it does not pass, uses xsl:message with @terminate='yes' to halt the process and echo the error message to std out:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xd" version="1.0"> <xsl:template match="/"> <!--Assert that /parent/value/@name == 'bob'--> <xsl:if test="not(/parent/value/@name='bob')"> <!-- if it does not, then terminate the transform and fail --> <xsl:message terminate="yes">name must be bob</xsl:message> </xsl:if> </xsl:template> </xsl:stylesheet>
Simply execute the XSLT against the file(s) that you want to validate.