summaryrefslogtreecommitdiff
path: root/manual/Tasks/junitreport.html
blob: c81c2cf6992c0c747f9ebc97917d29eeef2b01cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
<title>JUnitReport Task</title>
</head>

<body>

<h2 id="junitreport">JUnitReport</h2>
<h3>Description</h3>
<p>Merge the individual XML files generated by the <code>JUnit</code> task and eventually apply a
stylesheet on the resulting merged document to provide a browsable report of the testcases
results.</p>

<p><strong>Note</strong>: This task depends on external libraries not included in the Apache Ant
distribution. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more
information.</p>

<h3>Requirements</h3>

<p>The task needs Apache <a href="https://xml.apache.org/xalan-j/" target="_top">Xalan 2.4.1+ or
Xalan XSLTC</a> (JDK 1.4 contains a version of Xalan 2.x, while JDK 1.5 ships with a version of
XSLTC). JDK 1.4.2-01 and later ships with a bundled Xalan 2.4.1+, meaning that JDKs prior to version
1.4.2-01 won't work out of the box. The table below summarize the compatibility status.</p>
<table>
<tr><th>Xalan</th><th>Sun JDK Bundle</th><th>Status<th></tr>
<tr><td>2.4.1+</td><td>JDK 1.4.2-01+</td><td>OK</td></tr>
<tr><td>XSLTC</td><td>JDK 1.5.x</td><td>OK</td></tr>
<tr><td>2.x</td><td>JDK 1.4.x</td><td><em><u>Deprecated</u>,
use <samp>${ant.home}/etc/junit-frames-xalan1.xsl</samp><br/>Upgrade Xalan using the JDK endorsement
mechanism</em></td></tr>
</table>

<p>In Ant 1.6.2, we had to decide between supporting Xalan 1/Xalan 2.4.1- and Xalan 2.4.1+/XSLTC,
because there was no way to support both couples at the same time.</p>
<p><em>Since Ant 1.7</em>, we dropped support for Xalan 1, because Xalan 1 was not available anymore
for quite some time.</p>

<h3>Parameters</h3>
<table class="attr">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
    <th>Required</th>
  </tr>
  <tr>
    <td>tofile</td>
    <td>The name of the XML file that will aggregate all individual XML testsuites previously
      generated by the <code>JUnit</code> task.</td>
    <td>No; defaults to <samp>TESTS-TestSuites.xml</samp></td>
  </tr>
  <tr>
    <td>todir</td>
    <td>The directory where the file resulting from the individual XML testsuite aggregation should
      be written.</td>
    <td>No; defaults to current directory</td>
  </tr>
</table>
<h3 id="nested">Parameters specified as nested elements</h3>
<h4>fileset</h4>
<p><code>junitreport</code> collects individual xml files generated by the <code>JUnit</code> task
using the nested <a href="../Types/fileset.html"><code>&lt;FileSet&gt;</code></a> element.</p>
<h4>report</h4>
<p>Generate a browsable report based on the document created by the merge.</p>
<h3>Parameters</h3>
<table class="attr">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
    <th>Required</th>
  </tr>
  <tr>
    <td>format</td>
    <td>The format of the generated report. Must be either <q>noframes</q> or <q>frames</q>.</td>
    <td>No; defaults to <q>frames</q></td>
  </tr>
  <tr>
    <td>styledir</td>
    <td>The directory where the stylesheets are defined. They must be conforming to the following
      conventions:
      <ul>
        <li><q>frames</q> format: the stylesheet must be named <samp>junit-frames.xsl</samp>,
          or <samp>junit-frames-saxon.xsl</samp> if you are using Saxon 9+.</li>
        <li><q>noframes</q> format: the stylesheet must be named <samp>junit-noframes.xsl</samp>,
          or <samp>junit-noframes-saxon.xsl</samp> if you are using Saxon 9+.</li>
      </ul>
    </td>
    <td>No; defaults to embedded stylesheets</td>
  </tr>
  <tr>
    <td>todir</td>
    <td>The directory where the files resulting from the transformation should be written to.</td>
    <td>No; defaults to current directory</td>
  </tr>
</table>
<p>Ant assumes the following concerning the <q>frames</q> and <q>noframes</q> formats:</p>
<ul>
  <li>The <q>frames</q> format uses a stylesheet which is generating output <em>only</em> by
    redirecting.</li>
  <li>The <q>noframes</q> format does not use redirecting and generates one file
    called <samp>junit-noframes.html</samp>.</li>
</ul>
<p>Custom versions of <samp>junit-frames.xsl</samp> or <samp>junit-noframes.xsl</samp> must adhere
to the above conventions.</p>

<h3>Nested element of the report tag</h3>
<h4>param</h4>
<p><em>Since Ant 1.7</em>, the <var>report</var> tag supports nested <code>param</code> tags.  These
tags can pass XSL parameters to the stylesheet.</p>
<h3>Parameters</h3>
<table class="attr">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
    <th>Required</th>
  </tr>
  <tr>
    <td>name</td>
    <td>Name of the XSL parameter</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>expression</td>
    <td>Text value to be placed into the <code>param</code>.<br/>Was originally intended to be an
      XSL expression.</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>if</td>
    <td>The <code>param</code> will only be passed <a href="../properties.html#if+unless">if this
      property is set</a>.</td>
    <td>No</td>
  </tr>
  <tr>
    <td>unless</td>
    <td>The <code>param</code> will not be passed <a href="../properties.html#if+unless">if this
      property is set</a>.</td>
    <td>No</td>
  </tr>
</table>

<p>The built-in stylesheets support the following parameters:</p>
<table>
  <tr>
    <th>XSL Parameter</th>
    <th>Description</th>
    <th>Required</th>
  </tr>
  <tr>
    <td>TITLE</td>
    <td>Title used in <code>&lt;title&gt;</code> and <code>&lt;h1&gt;</code> tags</td>
    <td>No; defaults to <q>Unit Test Results</q></td>
  </tr>
</table>

<h4>classpath</h4>
<p><em>Since Ant 1.9.5</em>. Like for the <a href="../Tasks/style.html#classpath">XSLT task</a>, a
nested <code>&lt;classpath&gt;</code> will be used to load the processor.</p>

<h4>factory</h4>
<p><em>Since Ant 1.9.5</em>. Like for the <a href="../Tasks/style.html#factory">XSLT task</a>, a
nested <code>&lt;factory&gt;</code> can be used to specify factory settings.</p>

<h3>Example of report</h3>
<pre>
&lt;junitreport todir=&quot;./reports&quot;&gt;
    &lt;fileset dir=&quot;./reports&quot;&gt;
        &lt;include name=&quot;TEST-*.xml&quot;/&gt;
    &lt;/fileset&gt;
    &lt;report format=&quot;frames&quot; todir=&quot;./report/html&quot;/&gt;
&lt;/junitreport&gt;</pre>

<p>would generate a <samp>TESTS-TestSuites.xml</samp> file in the directory <samp>reports</samp> and
generate the default framed report in the directory <samp>report/html</samp>.</p>

<h3>Example of report with XSL params</h3>
<pre>
&lt;junitreport todir="${outputdir}"&gt;
    &lt;fileset dir="${jrdir}"&gt;
        &lt;include name="TEST-*.xml"/&gt;
    &lt;/fileset&gt;
    &lt;report todir="${outputdir}/html"
            styledir="junitreport"
            format="frames"&gt;
        &lt;param name="key1" expression="value1"/&gt;
        &lt;param name="key2" expression="value2"/&gt;
    &lt;/report&gt;
&lt;/junitreport&gt;</pre>

<p>This example requires a file called <samp>junitreport/junit-frames.xsl</samp>.  The XSL
parameters <q>key1</q> and <q>key2</q> will be passed to the XSL transformation.</p>

</body>
</html>