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

junit-noframes.xsl 15 kB

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