2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
3 xmlns:lxslt="http://xml.apache.org/xslt"
4 xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils">
5 <xsl:output method="html" indent="yes" encoding="US-ASCII"
6 doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
7 <xsl:decimal-format decimal-separator="." grouping-separator="," />
9 Licensed to the Apache Software Foundation (ASF) under one or more
10 contributor license agreements. See the NOTICE file distributed with
11 this work for additional information regarding copyright ownership.
12 The ASF licenses this file to You under the Apache License, Version 2.0
13 (the "License"); you may not use this file except in compliance with
14 the License. You may obtain a copy of the License at
16 http://www.apache.org/licenses/LICENSE-2.0
18 Unless required by applicable law or agreed to in writing, software
19 distributed under the License is distributed on an "AS IS" BASIS,
20 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 See the License for the specific language governing permissions and
22 limitations under the License.
25 <xsl:param name="TITLE">Unit Test Results.</xsl:param>
29 Sample stylesheet to be used with Ant JUnitReport output.
31 It creates a non-framed report that can be useful to send via
35 <xsl:template match="testsuites">
38 <title><xsl:value-of select="$TITLE"/></title>
39 <style type="text/css">
41 font:normal 68% verdana,arial,helvetica;
44 table tr td, table tr th {
58 margin-top:0.5em; margin-bottom:1.0em;
61 margin: 0px 0px 5px; font: 165% verdana,arial,helvetica
64 margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica
67 margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica
70 margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
73 margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
76 margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
79 font-weight:bold; color:red;
82 font-weight:bold; color:purple;
88 <script type="text/javascript" language="JavaScript">
89 var TestCases = new Array();
91 <xsl:for-each select="./testsuite">
92 <xsl:apply-templates select="properties"/>
96 <script type="text/javascript" language="JavaScript"><![CDATA[
97 function displayProperties (name) {
98 var win = window.open('','JUnitSystemProperties','scrollbars=1,resizable=1');
99 var doc = win.document;
101 doc.write("<html><head><title>Properties of " + name + "</title>");
103 doc.write("body {font:normal 68% verdana,arial,helvetica; color:#000000; }");
104 doc.write("table tr td, table tr th { font-size: 68%; }");
105 doc.write("table.properties { border-collapse:collapse; border-left:solid 1 #cccccc; border-top:solid 1 #cccccc; padding:5px; }");
106 doc.write("table.properties th { text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#eeeeee; }");
107 doc.write("table.properties td { font:normal; text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#fffffff; }");
108 doc.write("h3 { margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica }");
109 doc.write("</style>");
110 doc.write("</head><body>");
111 doc.write("<h3>Properties of " + name + "</h3>");
112 doc.write("<div align=\"right\"><a href=\"javascript:window.close();\">Close</a></div>");
113 doc.write("<table class='properties'>");
114 doc.write("<tr><th>Name</th><th>Value</th></tr>");
115 for (prop in TestCases[name]) {
116 doc.write("<tr><th>" + prop + "</th><td>" + TestCases[name][prop] + "</td></tr>");
118 doc.write("</table>");
119 doc.write("</body></html>");
128 <xsl:call-template name="pageHeader"/>
130 <!-- Summary part -->
131 <xsl:call-template name="summary"/>
132 <hr size="1" width="95%" align="left"/>
134 <!-- Package List part -->
135 <xsl:call-template name="packagelist"/>
136 <hr size="1" width="95%" align="left"/>
138 <!-- For each package create its part -->
139 <xsl:call-template name="packages"/>
140 <hr size="1" width="95%" align="left"/>
142 <!-- For each class create the part -->
143 <xsl:call-template name="classes"/>
151 <!-- ================================================================== -->
152 <!-- Write a list of all packages with an hyperlink to the anchor of -->
153 <!-- of the package name. -->
154 <!-- ================================================================== -->
155 <xsl:template name="packagelist">
157 Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers.
158 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
159 <xsl:call-template name="testsuite.test.header"/>
160 <!-- list all packages recursively -->
161 <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
162 <xsl:sort select="@package"/>
163 <xsl:variable name="testsuites-in-package" select="/testsuites/testsuite[./@package = current()/@package]"/>
164 <xsl:variable name="testCount" select="sum($testsuites-in-package/@tests)"/>
165 <xsl:variable name="errorCount" select="sum($testsuites-in-package/@errors)"/>
166 <xsl:variable name="failureCount" select="sum($testsuites-in-package/@failures)"/>
167 <xsl:variable name="timeCount" select="sum($testsuites-in-package/@time)"/>
169 <!-- write a summary for the package -->
171 <!-- set a nice color depending if there is an error/failure -->
172 <xsl:attribute name="class">
174 <xsl:when test="$failureCount > 0">Failure</xsl:when>
175 <xsl:when test="$errorCount > 0">Error</xsl:when>
178 <td><a href="#{@package}"><xsl:value-of select="@package"/></a></td>
179 <td><xsl:value-of select="$testCount"/></td>
180 <td><xsl:value-of select="$errorCount"/></td>
181 <td><xsl:value-of select="$failureCount"/></td>
183 <xsl:call-template name="display-time">
184 <xsl:with-param name="value" select="$timeCount"/>
187 <td><xsl:value-of select="$testsuites-in-package/@timestamp"/></td>
188 <td><xsl:value-of select="$testsuites-in-package/@hostname"/></td>
195 <!-- ================================================================== -->
196 <!-- Write a package level report -->
197 <!-- It creates a table with values from the document: -->
198 <!-- Name | Tests | Errors | Failures | Time -->
199 <!-- ================================================================== -->
200 <xsl:template name="packages">
201 <!-- create an anchor to this package name -->
202 <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
203 <xsl:sort select="@package"/>
204 <a name="{@package}"></a>
205 <h3>Package <xsl:value-of select="@package"/></h3>
207 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
208 <xsl:call-template name="testsuite.test.header"/>
210 <!-- match the testsuites of this package -->
211 <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/>
213 <a href="#top">Back to top</a>
219 <xsl:template name="classes">
220 <xsl:for-each select="testsuite">
221 <xsl:sort select="@name"/>
222 <!-- create an anchor to this class name -->
223 <a name="{@name}"></a>
224 <h3>TestCase <xsl:value-of select="@name"/></h3>
226 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
227 <xsl:call-template name="testcase.test.header"/>
229 test can even not be started at all (failure to load the class)
230 so report the error directly
232 <xsl:if test="./error">
234 <td colspan="4"><xsl:apply-templates select="./error"/></td>
237 <xsl:apply-templates select="./testcase" mode="print.test"/>
239 <div class="Properties">
241 <xsl:attribute name="href">javascript:displayProperties('<xsl:value-of select="@package"/>.<xsl:value-of select="@name"/>');</xsl:attribute>
247 <a href="#top">Back to top</a>
251 <xsl:template name="summary">
253 <xsl:variable name="testCount" select="sum(testsuite/@tests)"/>
254 <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
255 <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/>
256 <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
257 <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>
258 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
263 <th>Success rate</th>
267 <xsl:attribute name="class">
269 <xsl:when test="$failureCount > 0">Failure</xsl:when>
270 <xsl:when test="$errorCount > 0">Error</xsl:when>
273 <td><xsl:value-of select="$testCount"/></td>
274 <td><xsl:value-of select="$failureCount"/></td>
275 <td><xsl:value-of select="$errorCount"/></td>
277 <xsl:call-template name="display-percent">
278 <xsl:with-param name="value" select="$successRate"/>
282 <xsl:call-template name="display-time">
283 <xsl:with-param name="value" select="$timeCount"/>
289 <table border="0" width="95%">
291 <td style="text-align: justify;">
292 Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated.
299 Write properties into a JavaScript data structure.
300 This is based on the original idea by Erik Hatcher (ehatcher@apache.org)
302 <xsl:template match="properties">
303 cur = TestCases['<xsl:value-of select="../@package"/>.<xsl:value-of select="../@name"/>'] = new Array();
304 <xsl:for-each select="property">
305 <xsl:sort select="@name"/>
306 cur['<xsl:value-of select="@name"/>'] = '<xsl:call-template name="JS-escape"><xsl:with-param name="string" select="@value"/></xsl:call-template>';
311 <xsl:template name="pageHeader">
312 <h1><xsl:value-of select="$TITLE"/></h1>
315 <td align="left"></td>
316 <td align="right">Designed for use with <a href='http://www.junit.org'>JUnit</a> and <a href='http://ant.apache.org/ant'>Ant</a>.</td>
322 <xsl:template match="testsuite" mode="header">
324 <th width="80%">Name</th>
328 <th nowrap="nowrap">Time(s)</th>
332 <!-- class header -->
333 <xsl:template name="testsuite.test.header">
335 <th width="80%">Name</th>
339 <th nowrap="nowrap">Time(s)</th>
340 <th nowrap="nowrap">Time Stamp</th>
345 <!-- method header -->
346 <xsl:template name="testcase.test.header">
350 <th width="80%">Type</th>
351 <th nowrap="nowrap">Time(s)</th>
356 <!-- class information -->
357 <xsl:template match="testsuite" mode="print.test">
359 <!-- set a nice color depending if there is an error/failure -->
360 <xsl:attribute name="class">
362 <xsl:when test="@failures[.> 0]">Failure</xsl:when>
363 <xsl:when test="@errors[.> 0]">Error</xsl:when>
367 <!-- print testsuite information -->
368 <td><a href="#{@name}"><xsl:value-of select="@name"/></a></td>
369 <td><xsl:value-of select="@tests"/></td>
370 <td><xsl:value-of select="@errors"/></td>
371 <td><xsl:value-of select="@failures"/></td>
373 <xsl:call-template name="display-time">
374 <xsl:with-param name="value" select="@time"/>
377 <td><xsl:apply-templates select="@timestamp"/></td>
378 <td><xsl:apply-templates select="@hostname"/></td>
382 <xsl:template match="testcase" mode="print.test">
384 <xsl:attribute name="class">
386 <xsl:when test="failure | error">Error</xsl:when>
389 <td><xsl:value-of select="@name"/></td>
391 <xsl:when test="failure">
393 <td><xsl:apply-templates select="failure"/></td>
395 <xsl:when test="error">
397 <td><xsl:apply-templates select="error"/></td>
405 <xsl:call-template name="display-time">
406 <xsl:with-param name="value" select="@time"/>
413 <xsl:template match="failure">
414 <xsl:call-template name="display-failures"/>
417 <xsl:template match="error">
418 <xsl:call-template name="display-failures"/>
421 <!-- Style for the error and failure in the tescase template -->
422 <xsl:template name="display-failures">
424 <xsl:when test="not(@message)">N/A</xsl:when>
426 <xsl:value-of select="@message"/>
429 <!-- display the stacktrace -->
432 <xsl:call-template name="br-replace">
433 <xsl:with-param name="word" select="."/>
436 <!-- the later is better but might be problematic for non-21" monitors... -->
437 <!--pre><xsl:value-of select="."/></pre-->
440 <xsl:template name="JS-escape">
441 <xsl:param name="string"/>
442 <xsl:param name="tmp1" select="stringutils:replace(string($string),'\','\\')"/>
443 <xsl:param name="tmp2" select="stringutils:replace(string($tmp1),"'","\'")"/>
444 <xsl:value-of select="$tmp2"/>
449 template that will convert a carriage return into a br tag
450 @param word the text from which to convert CR to BR tag
452 <xsl:template name="br-replace">
453 <xsl:param name="word"/>
454 <xsl:value-of disable-output-escaping="yes" select='stringutils:replace(string($word),"
","<br/>")'/>
457 <xsl:template name="display-time">
458 <xsl:param name="value"/>
459 <xsl:value-of select="format-number($value,'0.000')"/>
462 <xsl:template name="display-percent">
463 <xsl:param name="value"/>
464 <xsl:value-of select="format-number($value,'0.00%')"/>