You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

junit-noframes.xsl 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  2. xmlns:lxslt="http://xml.apache.org/xslt"
  3. xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils">
  4. <xsl:output method="html" indent="yes" encoding="US-ASCII"
  5. doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
  6. <xsl:decimal-format decimal-separator="." grouping-separator="," />
  7. <!--
  8. Copyright 2001-2004 The Apache Software Foundation
  9. Licensed under the Apache License, Version 2.0 (the "License");
  10. you may not use this file except in compliance with the License.
  11. You may obtain a copy of the License at
  12. http://www.apache.org/licenses/LICENSE-2.0
  13. Unless required by applicable law or agreed to in writing, software
  14. distributed under the License is distributed on an "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18. -->
  19. <!--
  20. Sample stylesheet to be used with Ant JUnitReport output.
  21. It creates a non-framed report that can be useful to send via
  22. e-mail or such.
  23. @author Stephane Bailliez <a href="mailto:sbailliez@apache.org"/>
  24. @author Erik Hatcher <a href="mailto:ehatcher@apache.org"/>
  25. -->
  26. <xsl:template match="testsuites">
  27. <html>
  28. <head>
  29. <title>Unit Test Results</title>
  30. <style type="text/css">
  31. body {
  32. font:normal 68% verdana,arial,helvetica;
  33. color:#000000;
  34. }
  35. table tr td, table tr th {
  36. font-size: 68%;
  37. }
  38. table.details tr th{
  39. font-weight: bold;
  40. text-align:left;
  41. background:#a6caf0;
  42. }
  43. table.details tr td{
  44. background:#eeeee0;
  45. }
  46. p {
  47. line-height:1.5em;
  48. margin-top:0.5em; margin-bottom:1.0em;
  49. }
  50. h1 {
  51. margin: 0px 0px 5px; font: 165% verdana,arial,helvetica
  52. }
  53. h2 {
  54. margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica
  55. }
  56. h3 {
  57. margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica
  58. }
  59. h4 {
  60. margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
  61. }
  62. h5 {
  63. margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
  64. }
  65. h6 {
  66. margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica
  67. }
  68. .Error {
  69. font-weight:bold; color:red;
  70. }
  71. .Failure {
  72. font-weight:bold; color:purple;
  73. }
  74. .Properties {
  75. text-align:right;
  76. }
  77. </style>
  78. <script type="text/javascript" language="JavaScript">
  79. var TestCases = new Array();
  80. var cur;
  81. <xsl:for-each select="./testsuite">
  82. <xsl:apply-templates select="properties"/>
  83. </xsl:for-each>
  84. </script>
  85. <script type="text/javascript" language="JavaScript"><![CDATA[
  86. function displayProperties (name) {
  87. var win = window.open('','JUnitSystemProperties','scrollbars=1,resizable=1');
  88. var doc = win.document.open();
  89. doc.write("<html><head><title>Properties of " + name + "</title>");
  90. doc.write("<style>")
  91. doc.write("body {font:normal 68% verdana,arial,helvetica; color:#000000; }");
  92. doc.write("table tr td, table tr th { font-size: 68%; }");
  93. doc.write("table.properties { border-collapse:collapse; border-left:solid 1 #cccccc; border-top:solid 1 #cccccc; padding:5px; }");
  94. doc.write("table.properties th { text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#eeeeee; }");
  95. doc.write("table.properties td { font:normal; text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#fffffff; }");
  96. doc.write("h3 { margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica }");
  97. doc.write("</style>");
  98. doc.write("</head><body>");
  99. doc.write("<h3>Properties of " + name + "</h3>");
  100. doc.write("<div align=\"right\"><a href=\"javascript:window.close();\">Close</a></div>");
  101. doc.write("<table class='properties'>");
  102. doc.write("<tr><th>Name</th><th>Value</th></tr>");
  103. for (prop in TestCases[name]) {
  104. doc.write("<tr><th>" + prop + "</th><td>" + TestCases[name][prop] + "</td></tr>");
  105. }
  106. doc.write("</table>");
  107. doc.write("</body></html>");
  108. doc.close();
  109. win.focus();
  110. }
  111. ]]>
  112. </script>
  113. </head>
  114. <body>
  115. <a name="top"></a>
  116. <xsl:call-template name="pageHeader"/>
  117. <!-- Summary part -->
  118. <xsl:call-template name="summary"/>
  119. <hr size="1" width="95%" align="left"/>
  120. <!-- Package List part -->
  121. <xsl:call-template name="packagelist"/>
  122. <hr size="1" width="95%" align="left"/>
  123. <!-- For each package create its part -->
  124. <xsl:call-template name="packages"/>
  125. <hr size="1" width="95%" align="left"/>
  126. <!-- For each class create the part -->
  127. <xsl:call-template name="classes"/>
  128. </body>
  129. </html>
  130. </xsl:template>
  131. <!-- ================================================================== -->
  132. <!-- Write a list of all packages with an hyperlink to the anchor of -->
  133. <!-- of the package name. -->
  134. <!-- ================================================================== -->
  135. <xsl:template name="packagelist">
  136. <h2>Packages</h2>
  137. Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers.
  138. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  139. <xsl:call-template name="testsuite.test.header"/>
  140. <!-- list all packages recursively -->
  141. <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
  142. <xsl:sort select="@package"/>
  143. <xsl:variable name="testsuites-in-package" select="/testsuites/testsuite[./@package = current()/@package]"/>
  144. <xsl:variable name="testCount" select="sum($testsuites-in-package/@tests)"/>
  145. <xsl:variable name="errorCount" select="sum($testsuites-in-package/@errors)"/>
  146. <xsl:variable name="failureCount" select="sum($testsuites-in-package/@failures)"/>
  147. <xsl:variable name="timeCount" select="sum($testsuites-in-package/@time)"/>
  148. <!-- write a summary for the package -->
  149. <tr valign="top">
  150. <!-- set a nice color depending if there is an error/failure -->
  151. <xsl:attribute name="class">
  152. <xsl:choose>
  153. <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
  154. <xsl:when test="$errorCount &gt; 0">Error</xsl:when>
  155. </xsl:choose>
  156. </xsl:attribute>
  157. <td><a href="#{@package}"><xsl:value-of select="@package"/></a></td>
  158. <td><xsl:value-of select="$testCount"/></td>
  159. <td><xsl:value-of select="$errorCount"/></td>
  160. <td><xsl:value-of select="$failureCount"/></td>
  161. <td>
  162. <xsl:call-template name="display-time">
  163. <xsl:with-param name="value" select="$timeCount"/>
  164. </xsl:call-template>
  165. </td>
  166. </tr>
  167. </xsl:for-each>
  168. </table>
  169. </xsl:template>
  170. <!-- ================================================================== -->
  171. <!-- Write a package level report -->
  172. <!-- It creates a table with values from the document: -->
  173. <!-- Name | Tests | Errors | Failures | Time -->
  174. <!-- ================================================================== -->
  175. <xsl:template name="packages">
  176. <!-- create an anchor to this package name -->
  177. <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
  178. <xsl:sort select="@package"/>
  179. <a name="{@package}"></a>
  180. <h3>Package <xsl:value-of select="@package"/></h3>
  181. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  182. <xsl:call-template name="testsuite.test.header"/>
  183. <!-- match the testsuites of this package -->
  184. <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/>
  185. </table>
  186. <a href="#top">Back to top</a>
  187. <p/>
  188. <p/>
  189. </xsl:for-each>
  190. </xsl:template>
  191. <xsl:template name="classes">
  192. <xsl:for-each select="testsuite">
  193. <xsl:sort select="@name"/>
  194. <!-- create an anchor to this class name -->
  195. <a name="{@name}"></a>
  196. <h3>TestCase <xsl:value-of select="@name"/></h3>
  197. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  198. <xsl:call-template name="testcase.test.header"/>
  199. <!--
  200. test can even not be started at all (failure to load the class)
  201. so report the error directly
  202. -->
  203. <xsl:if test="./error">
  204. <tr class="Error">
  205. <td colspan="4"><xsl:apply-templates select="./error"/></td>
  206. </tr>
  207. </xsl:if>
  208. <xsl:apply-templates select="./testcase" mode="print.test"/>
  209. </table>
  210. <div class="Properties">
  211. <a>
  212. <xsl:attribute name="href">javascript:displayProperties('<xsl:value-of select="@package"/>.<xsl:value-of select="@name"/>');</xsl:attribute>
  213. Properties &#187;
  214. </a>
  215. </div>
  216. <p/>
  217. <a href="#top">Back to top</a>
  218. </xsl:for-each>
  219. </xsl:template>
  220. <xsl:template name="summary">
  221. <h2>Summary</h2>
  222. <xsl:variable name="testCount" select="sum(testsuite/@tests)"/>
  223. <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
  224. <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/>
  225. <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
  226. <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>
  227. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  228. <tr valign="top">
  229. <th>Tests</th>
  230. <th>Failures</th>
  231. <th>Errors</th>
  232. <th>Success rate</th>
  233. <th>Time</th>
  234. </tr>
  235. <tr valign="top">
  236. <xsl:attribute name="class">
  237. <xsl:choose>
  238. <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
  239. <xsl:when test="$errorCount &gt; 0">Error</xsl:when>
  240. </xsl:choose>
  241. </xsl:attribute>
  242. <td><xsl:value-of select="$testCount"/></td>
  243. <td><xsl:value-of select="$failureCount"/></td>
  244. <td><xsl:value-of select="$errorCount"/></td>
  245. <td>
  246. <xsl:call-template name="display-percent">
  247. <xsl:with-param name="value" select="$successRate"/>
  248. </xsl:call-template>
  249. </td>
  250. <td>
  251. <xsl:call-template name="display-time">
  252. <xsl:with-param name="value" select="$timeCount"/>
  253. </xsl:call-template>
  254. </td>
  255. </tr>
  256. </table>
  257. <table border="0" width="95%">
  258. <tr>
  259. <td style="text-align: justify;">
  260. Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated.
  261. </td>
  262. </tr>
  263. </table>
  264. </xsl:template>
  265. <!--
  266. Write properties into a JavaScript data structure.
  267. This is based on the original idea by Erik Hatcher (ehatcher@apache.org)
  268. -->
  269. <xsl:template match="properties">
  270. cur = TestCases['<xsl:value-of select="../@package"/>.<xsl:value-of select="../@name"/>'] = new Array();
  271. <xsl:for-each select="property">
  272. <xsl:sort select="@name"/>
  273. cur['<xsl:value-of select="@name"/>'] = '<xsl:call-template name="JS-escape"><xsl:with-param name="string" select="@value"/></xsl:call-template>';
  274. </xsl:for-each>
  275. </xsl:template>
  276. <!-- Page HEADER -->
  277. <xsl:template name="pageHeader">
  278. <h1>Unit Test Results</h1>
  279. <table width="100%">
  280. <tr>
  281. <td align="left"></td>
  282. <td align="right">Designed for use with <a href='http://www.junit.org'>JUnit</a> and <a href='http://jakarta.apache.org/ant'>Ant</a>.</td>
  283. </tr>
  284. </table>
  285. <hr size="1"/>
  286. </xsl:template>
  287. <xsl:template match="testsuite" mode="header">
  288. <tr valign="top">
  289. <th width="80%">Name</th>
  290. <th>Tests</th>
  291. <th>Errors</th>
  292. <th>Failures</th>
  293. <th nowrap="nowrap">Time(s)</th>
  294. </tr>
  295. </xsl:template>
  296. <!-- class header -->
  297. <xsl:template name="testsuite.test.header">
  298. <tr valign="top">
  299. <th width="80%">Name</th>
  300. <th>Tests</th>
  301. <th>Errors</th>
  302. <th>Failures</th>
  303. <th nowrap="nowrap">Time(s)</th>
  304. </tr>
  305. </xsl:template>
  306. <!-- method header -->
  307. <xsl:template name="testcase.test.header">
  308. <tr valign="top">
  309. <th>Name</th>
  310. <th>Status</th>
  311. <th width="80%">Type</th>
  312. <th nowrap="nowrap">Time(s)</th>
  313. </tr>
  314. </xsl:template>
  315. <!-- class information -->
  316. <xsl:template match="testsuite" mode="print.test">
  317. <tr valign="top">
  318. <!-- set a nice color depending if there is an error/failure -->
  319. <xsl:attribute name="class">
  320. <xsl:choose>
  321. <xsl:when test="@failures[.&gt; 0]">Failure</xsl:when>
  322. <xsl:when test="@errors[.&gt; 0]">Error</xsl:when>
  323. </xsl:choose>
  324. </xsl:attribute>
  325. <!-- print testsuite information -->
  326. <td><a href="#{@name}"><xsl:value-of select="@name"/></a></td>
  327. <td><xsl:value-of select="@tests"/></td>
  328. <td><xsl:value-of select="@errors"/></td>
  329. <td><xsl:value-of select="@failures"/></td>
  330. <td>
  331. <xsl:call-template name="display-time">
  332. <xsl:with-param name="value" select="@time"/>
  333. </xsl:call-template>
  334. </td>
  335. </tr>
  336. </xsl:template>
  337. <xsl:template match="testcase" mode="print.test">
  338. <tr valign="top">
  339. <xsl:attribute name="class">
  340. <xsl:choose>
  341. <xsl:when test="failure | error">Error</xsl:when>
  342. </xsl:choose>
  343. </xsl:attribute>
  344. <td><xsl:value-of select="@name"/></td>
  345. <xsl:choose>
  346. <xsl:when test="failure">
  347. <td>Failure</td>
  348. <td><xsl:apply-templates select="failure"/></td>
  349. </xsl:when>
  350. <xsl:when test="error">
  351. <td>Error</td>
  352. <td><xsl:apply-templates select="error"/></td>
  353. </xsl:when>
  354. <xsl:otherwise>
  355. <td>Success</td>
  356. <td></td>
  357. </xsl:otherwise>
  358. </xsl:choose>
  359. <td>
  360. <xsl:call-template name="display-time">
  361. <xsl:with-param name="value" select="@time"/>
  362. </xsl:call-template>
  363. </td>
  364. </tr>
  365. </xsl:template>
  366. <xsl:template match="failure">
  367. <xsl:call-template name="display-failures"/>
  368. </xsl:template>
  369. <xsl:template match="error">
  370. <xsl:call-template name="display-failures"/>
  371. </xsl:template>
  372. <!-- Style for the error and failure in the tescase template -->
  373. <xsl:template name="display-failures">
  374. <xsl:choose>
  375. <xsl:when test="not(@message)">N/A</xsl:when>
  376. <xsl:otherwise>
  377. <xsl:value-of select="@message"/>
  378. </xsl:otherwise>
  379. </xsl:choose>
  380. <!-- display the stacktrace -->
  381. <code>
  382. <br/><br/>
  383. <xsl:call-template name="br-replace">
  384. <xsl:with-param name="word" select="."/>
  385. </xsl:call-template>
  386. </code>
  387. <!-- the later is better but might be problematic for non-21" monitors... -->
  388. <!--pre><xsl:value-of select="."/></pre-->
  389. </xsl:template>
  390. <xsl:template name="JS-escape">
  391. <xsl:param name="string"/>
  392. <xsl:param name="tmp1" select="stringutils:replace(string($string),'\','\\')"/>
  393. <xsl:param name="tmp2" select="stringutils:replace(string($tmp1),&quot;'&quot;,&quot;\&apos;&quot;)"/>
  394. <xsl:value-of select="$tmp2"/>
  395. </xsl:template>
  396. <!--
  397. template that will convert a carriage return into a br tag
  398. @param word the text from which to convert CR to BR tag
  399. -->
  400. <xsl:template name="br-replace">
  401. <xsl:param name="word"/>
  402. <xsl:param name="br"><br/></xsl:param>
  403. <xsl:value-of select='stringutils:replace(string($word),"&#xA;",$br)'/>
  404. </xsl:template>
  405. <xsl:template name="display-time">
  406. <xsl:param name="value"/>
  407. <xsl:value-of select="format-number($value,'0.000')"/>
  408. </xsl:template>
  409. <xsl:template name="display-percent">
  410. <xsl:param name="value"/>
  411. <xsl:value-of select="format-number($value,'0.00%')"/>
  412. </xsl:template>
  413. </xsl:stylesheet>