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 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  2. <!-- ======================================================================
  3. Stylesheet to transform an XML file generated by the Ant MAudit task into
  4. a set of JavaDoc-like HTML page to make pages more convenient to be browsed.
  5. It use the Xalan redirect extension to write to multiple output files.
  6. Note: HTML output can be made much more clean by removing non css attributes
  7. ====================================================================== -->
  8. <xsl:output method="html" indent="yes"/>
  9. <xsl:decimal-format decimal-separator="." grouping-separator="," />
  10. <xsl:template match="testsuites">
  11. <HTML>
  12. <HEAD>
  13. <style type="text/css">
  14. BODY {
  15. font:normal 68% verdana,arial,helvetica;
  16. color:#000000;
  17. }
  18. TABLE TR TD, TABLE TR TH {
  19. font-size: 68%;
  20. }
  21. TABLE.details TR TH{
  22. font-weight: bold;
  23. text-align:left;
  24. background:#A6CAF0;
  25. }
  26. TABLE.details TR TD{
  27. background:#EEEEE0;
  28. }
  29. P {
  30. line-height:1.5em;
  31. margin-top:0.5em; margin-bottom:1.0em;
  32. }
  33. H1 {
  34. MARGIN: 0px 0px 5px; FONT: 165% verdana,arial,helvetica
  35. }
  36. H2 {
  37. MARGIN-TOP: 1em; MARGIN-BOTTOM: 0.5em; FONT: bold 125% verdana,arial,helvetica
  38. }
  39. H3 {
  40. MARGIN-BOTTOM: 0.5em; FONT: bold 115% verdana,arial,helvetica
  41. }
  42. H4 {
  43. MARGIN-BOTTOM: 0.5em; FONT: bold 100% verdana,arial,helvetica
  44. }
  45. H5 {
  46. MARGIN-BOTTOM: 0.5em; FONT: bold 100% verdana,arial,helvetica
  47. }
  48. H6 {
  49. MARGIN-BOTTOM: 0.5em; FONT: bold 100% verdana,arial,helvetica
  50. }
  51. .Error {
  52. font-weight:bold; color:red;
  53. }
  54. .Failure {
  55. font-weight:bold; color:purple;
  56. }
  57. </style>
  58. </HEAD>
  59. <body>
  60. <a name="#top"></a>
  61. <xsl:call-template name="pageHeader"/>
  62. <!-- Summary part -->
  63. <xsl:call-template name="summary"/>
  64. <hr size="1" width="95%" align="left"/>
  65. <!-- Package List part -->
  66. <xsl:call-template name="packagelist"/>
  67. <hr size="1" width="95%" align="left"/>
  68. <!-- For each package create its part -->
  69. <xsl:call-template name="packages"/>
  70. <hr size="1" width="95%" align="left"/>
  71. <!-- For each class create the part -->
  72. <xsl:call-template name="classes"/>
  73. </body>
  74. </HTML>
  75. </xsl:template>
  76. <!-- ================================================================== -->
  77. <!-- Write a list of all packages with an hyperlink to the anchor of -->
  78. <!-- of the package name. -->
  79. <!-- ================================================================== -->
  80. <xsl:template name="packagelist">
  81. <h2>Packages</h2>
  82. Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers.
  83. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  84. <xsl:call-template name="testsuite.test.header"/>
  85. <!-- list all packages recursively -->
  86. <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
  87. <xsl:sort select="@package"/>
  88. <xsl:variable name="testsuites-in-package" select="/testsuites/testsuite[./@package = current()/@package]"/>
  89. <xsl:variable name="testCount" select="sum($testsuites-in-package/@tests)"/>
  90. <xsl:variable name="errorCount" select="sum($testsuites-in-package/@errors)"/>
  91. <xsl:variable name="failureCount" select="sum($testsuites-in-package/@failures)"/>
  92. <xsl:variable name="timeCount" select="sum($testsuites-in-package/@time)"/>
  93. <!-- write a summary for the package -->
  94. <tr valign="top">
  95. <!-- set a nice color depending if there is an error/failure -->
  96. <xsl:attribute name="class">
  97. <xsl:choose>
  98. <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
  99. <xsl:when test="$errorCount &gt; 0">Error</xsl:when>
  100. </xsl:choose>
  101. </xsl:attribute>
  102. <td><a href="#{@package}"><xsl:value-of select="@package"/></a></td>
  103. <td><xsl:value-of select="$testCount"/></td>
  104. <td><xsl:value-of select="$errorCount"/></td>
  105. <td><xsl:value-of select="$failureCount"/></td>
  106. <td>
  107. <xsl:call-template name="display-time">
  108. <xsl:with-param name="value" select="$timeCount"/>
  109. </xsl:call-template>
  110. </td>
  111. </tr>
  112. </xsl:for-each>
  113. </table>
  114. </xsl:template>
  115. <!-- ================================================================== -->
  116. <!-- Write a package level report -->
  117. <!-- It creates a table with values from the document: -->
  118. <!-- Name | Tests | Errors | Failures | Time -->
  119. <!-- ================================================================== -->
  120. <xsl:template name="packages">
  121. <!-- create an anchor to this package name -->
  122. <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
  123. <xsl:sort select="@package"/>
  124. <a name="#{@package}"></a>
  125. <h3>Package <xsl:value-of select="@package"/></h3>
  126. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  127. <xsl:call-template name="testsuite.test.header"/>
  128. <!-- match the testsuites of this package -->
  129. <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/>
  130. </table>
  131. <a href="#top">Back to top</a>
  132. <p/>
  133. <p/>
  134. </xsl:for-each>
  135. </xsl:template>
  136. <xsl:template name="classes">
  137. <xsl:for-each select="testsuite">
  138. <xsl:sort select="@name"/>
  139. <!-- create an anchor to this class name -->
  140. <a name="#{@name}"></a>
  141. <h3>TestCase <xsl:value-of select="@name"/></h3>
  142. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  143. <!-- Header -->
  144. <xsl:call-template name="testcase.test.header"/>
  145. <!-- match the testcases of this package -->
  146. <xsl:apply-templates select="testcase" mode="print.test"/>
  147. </table>
  148. <p/>
  149. <xsl:apply-templates select="properties"/>
  150. <a href="#top">Back to top</a>
  151. </xsl:for-each>
  152. </xsl:template>
  153. <xsl:template name="summary">
  154. <h2>Summary</h2>
  155. <xsl:variable name="testCount" select="sum(testsuite/@tests)"/>
  156. <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
  157. <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/>
  158. <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
  159. <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>
  160. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  161. <tr valign="top">
  162. <th>Tests</th>
  163. <th>Failures</th>
  164. <th>Errors</th>
  165. <th>Success rate</th>
  166. <th>Time</th>
  167. </tr>
  168. <tr valign="top">
  169. <xsl:attribute name="class">
  170. <xsl:choose>
  171. <xsl:when test="$failureCount &gt; 0">Failure</xsl:when>
  172. <xsl:when test="$errorCount &gt; 0">Error</xsl:when>
  173. </xsl:choose>
  174. </xsl:attribute>
  175. <td><xsl:value-of select="$testCount"/></td>
  176. <td><xsl:value-of select="$failureCount"/></td>
  177. <td><xsl:value-of select="$errorCount"/></td>
  178. <td>
  179. <xsl:call-template name="display-percent">
  180. <xsl:with-param name="value" select="$successRate"/>
  181. </xsl:call-template>
  182. </td>
  183. <td>
  184. <xsl:call-template name="display-time">
  185. <xsl:with-param name="value" select="$timeCount"/>
  186. </xsl:call-template>
  187. </td>
  188. </tr>
  189. </table>
  190. <table border="0" width="95%">
  191. <tr>
  192. <td style="text-align: justify;">
  193. Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated.
  194. </td>
  195. </tr>
  196. </table>
  197. </xsl:template>
  198. <xsl:template match="properties">
  199. <!--
  200. I have NO idea how to display properties ! :-(
  201. It takes an incredible amount of space in the page and it's
  202. really unreadable.
  203. <xsl:variable name="count" select="count(property)"/>
  204. <h3>System Properties</h3>
  205. <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
  206. <tr valign="top">
  207. <th>Name</th>
  208. <th>Value</th>
  209. </tr>
  210. <xsl:for-each select="property">
  211. <tr valign="top">
  212. <td><xsl:value-of select="@name"/></td>
  213. <td><xsl:value-of select="@value"/></td>
  214. </tr>
  215. </xsl:for-each>
  216. </table>
  217. -->
  218. </xsl:template>
  219. <!-- Page HEADER -->
  220. <xsl:template name="pageHeader">
  221. <h1>Unit Test Results</h1>
  222. <table width="100%">
  223. <tr>
  224. <td align="left"></td>
  225. <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>
  226. </tr>
  227. </table>
  228. <hr size="1"/>
  229. </xsl:template>
  230. <xsl:template match="testsuite" mode="header">
  231. <tr valign="top">
  232. <th width="80%">Name</th>
  233. <th>Tests</th>
  234. <th>Errors</th>
  235. <th>Failures</th>
  236. <th nowrap="nowrap">Time(s)</th>
  237. </tr>
  238. </xsl:template>
  239. <!-- class header -->
  240. <xsl:template name="testsuite.test.header">
  241. <tr valign="top">
  242. <th width="80%">Name</th>
  243. <th>Tests</th>
  244. <th>Errors</th>
  245. <th>Failures</th>
  246. <th nowrap="nowrap">Time(s)</th>
  247. </tr>
  248. </xsl:template>
  249. <!-- method header -->
  250. <xsl:template name="testcase.test.header">
  251. <tr valign="top">
  252. <th>Name</th>
  253. <th>Status</th>
  254. <th width="80%">Type</th>
  255. <th nowrap="nowrap">Time(s)</th>
  256. </tr>
  257. </xsl:template>
  258. <!-- class information -->
  259. <xsl:template match="testsuite" mode="print.test">
  260. <tr valign="top">
  261. <!-- set a nice color depending if there is an error/failure -->
  262. <xsl:attribute name="class">
  263. <xsl:choose>
  264. <xsl:when test="@failures[.&gt; 0]">Failure</xsl:when>
  265. <xsl:when test="@errors[.&gt; 0]">Error</xsl:when>
  266. </xsl:choose>
  267. </xsl:attribute>
  268. <!-- print testsuite information -->
  269. <td><a href="#{@name}"><xsl:value-of select="@name"/></a></td>
  270. <td><xsl:value-of select="@tests"/></td>
  271. <td><xsl:value-of select="@errors"/></td>
  272. <td><xsl:value-of select="@failures"/></td>
  273. <td>
  274. <xsl:call-template name="display-time">
  275. <xsl:with-param name="value" select="@time"/>
  276. </xsl:call-template>
  277. </td>
  278. </tr>
  279. </xsl:template>
  280. <xsl:template match="testcase" mode="print.test">
  281. <tr valign="top">
  282. <xsl:attribute name="class">
  283. <xsl:choose>
  284. <xsl:when test="failure | error">Error</xsl:when>
  285. </xsl:choose>
  286. </xsl:attribute>
  287. <td><xsl:value-of select="@name"/></td>
  288. <xsl:choose>
  289. <xsl:when test="failure">
  290. <td>Failure</td>
  291. <td><xsl:apply-templates select="failure"/></td>
  292. </xsl:when>
  293. <xsl:when test="error">
  294. <td>Error</td>
  295. <td><xsl:apply-templates select="error"/></td>
  296. </xsl:when>
  297. <xsl:otherwise>
  298. <td>Success</td>
  299. <td></td>
  300. </xsl:otherwise>
  301. </xsl:choose>
  302. <td>
  303. <xsl:call-template name="display-time">
  304. <xsl:with-param name="value" select="@time"/>
  305. </xsl:call-template>
  306. </td>
  307. </tr>
  308. </xsl:template>
  309. <!-- Note : the below template error and failure are the same style
  310. so just call the same style store in the toolkit template -->
  311. <xsl:template match="failure">
  312. <xsl:call-template name="display-failures"/>
  313. </xsl:template>
  314. <xsl:template match="error">
  315. <xsl:call-template name="display-failures"/>
  316. </xsl:template>
  317. <!-- Style for the error and failure in the tescase template -->
  318. <xsl:template name="display-failures">
  319. <xsl:choose>
  320. <xsl:when test="not(@message)">N/A</xsl:when>
  321. <xsl:otherwise>
  322. <xsl:value-of select="@message"/>
  323. </xsl:otherwise>
  324. </xsl:choose>
  325. <!-- display the stacktrace -->
  326. <code>
  327. <p/>
  328. <xsl:call-template name="br-replace">
  329. <xsl:with-param name="word" select="."/>
  330. </xsl:call-template>
  331. </code>
  332. <!-- the later is better but might be problematic for non-21" monitors... -->
  333. <!--pre><xsl:value-of select="."/></pre-->
  334. </xsl:template>
  335. <!--
  336. template that will convert a carriage return into a br tag
  337. @param word the text from which to convert CR to BR tag
  338. -->
  339. <xsl:template name="br-replace">
  340. <xsl:param name="word"/>
  341. <xsl:choose>
  342. <xsl:when test="contains($word,'&#xA;')">
  343. <xsl:value-of select="substring-before($word,'&#xA;')"/>
  344. <br/>
  345. <xsl:call-template name="br-replace">
  346. <xsl:with-param name="word" select="substring-after($word,'&#xA;')"/>
  347. </xsl:call-template>
  348. </xsl:when>
  349. <xsl:otherwise>
  350. <xsl:value-of select="$word"/>
  351. </xsl:otherwise>
  352. </xsl:choose>
  353. </xsl:template>
  354. <xsl:template name="display-time">
  355. <xsl:param name="value"/>
  356. <xsl:value-of select="format-number($value,'0.000')"/>
  357. </xsl:template>
  358. <xsl:template name="display-percent">
  359. <xsl:param name="value"/>
  360. <xsl:value-of select="format-number($value,'0.00%')"/>
  361. </xsl:template>
  362. </xsl:stylesheet>