Skip to content

Commit

Permalink
add xUnit compatible output option
Browse files Browse the repository at this point in the history
  • Loading branch information
robwhitby committed May 19, 2012
1 parent e0fe227 commit 87db217
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ declare function string-equality-example()
};
```

**xray** can output test results as HTML, XML, xUnit compatible XML, and plain text, so should be simple to integrate with your favourite build/ci server.

## Getting Started
* Clone/copy/symlink xray into the root directory of your project e.g.<br/>
`git clone git://github.com/robwhitby/xray.git`
Expand Down
2 changes: 1 addition & 1 deletion src/output/html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
'&amp;modules=', encode-for-uri($module-pattern),
'&amp;tests=', encode-for-uri($test-pattern),
'&amp;format=')"/>
View results as <a href="{$qs}xml">xml</a>&#160;<a href="{$qs}text">text</a>
View results as <a href="{$qs}xml">xml</a>&#160;|&#160;<a href="{$qs}xunit">xUnit</a>&#160;|&#160;<a href="{$qs}text">text</a>
</p>
</xsl:template>

Expand Down
63 changes: 63 additions & 0 deletions src/output/xunit.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xray="http://github.com/robwhitby/xray"
xmlns:xdmp="http://marklogic.com/xdmp"
xmlns:error="http://marklogic.com/xdmp/error"
version="2.0"
exclude-result-prefixes="xray xdmp error">

<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

<xsl:param name="test-dir"/>
<xsl:param name="module-pattern"/>
<xsl:param name="test-pattern"/>

<xsl:template match="xray:tests">
<testsuites
name="{$test-dir}"
errors="{count(//(error:error|xray:test[@result='error']))}"
failures="{count(//xray:test[@result='failed'])}"
skipped="{count(//xray:test[@result='ignored'])}"
tests="{count(//xray:test)}">
<xsl:apply-templates/>
</testsuites>
</xsl:template>

<xsl:template match="xray:module">
<testsuite
name="{@path}"
classname="{@path}"
errors="{count((error:error|xray:test[@result='error']))}"
failures="{count(xray:test[@result='failed'])}"
skipped="{count(xray:test[@result='ignored'])}"
tests="{count(xray:test)}">
<xsl:apply-templates/>
</testsuite>
</xsl:template>

<xsl:template match="xray:test">
<testcase
name="{@name}"
classname="{../@path}"
assertions="{count(xray:assert)}"
status="{@result}">
<xsl:apply-templates/>
<xsl:if test="@result = 'ignored'">
<skipped/>
</xsl:if>
</testcase>
</xsl:template>

<xsl:template match="xray:assert[@result = 'failed']">
<failure type="{@test}">expected: <xsl:value-of select="xdmp:quote(xray:expected/node())"/>, actual: <xsl:value-of select="xdmp:quote(xray:actual/node())"/>
</failure>
</xsl:template>

<xsl:template match="xray:assert"/>

<xsl:template match="error:error">
<error message="{error:message}">
<xsl:copy-of select="."/>
</error>
</xsl:template>

</xsl:stylesheet>
2 changes: 1 addition & 1 deletion src/utils.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ declare function transform(
{
if ($format eq "text") then xdmp:set-response-content-type("text/plain") else ()
,
if ($format = ("html", "text"))
if ($format ne "xml")
then
let $params := map:map()
let $_ := map:put($params, "test-dir", $test-dir)
Expand Down

0 comments on commit 87db217

Please sign in to comment.