Debian Codegraph @

documentation-sources/content/xdocs/dev/test.xml

raw
1 <?xml version="1.0"?>
2
3 <!--
4
5 Licensed to the Apache Software Foundation (ASF) under one or more
6 contributor license agreements. See the NOTICE file distributed with
7 this work for additional information regarding copyright ownership.
8 The ASF licenses this file to You under the Apache License, Version 2.0
9 (the "License"); you may not use this file except in compliance with
10 the License. You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 -->
21
22 <!-- ========================================================================= -->
23 <!-- author [email protected] -->
24 <!-- version $Id$ -->
25 <!-- ========================================================================= -->
26
27 <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
28 <document>
29 <header>
30 <title>Test infrastructure</title>
31 </header>
32
33 <body>
34 <p>
35 This document describes the Batik test infrastructure whose goals
36 are to:
37 </p>
38 <ul>
39 <li>make it easy to detect regressions,</li>
40 <li>make it easy to run test suites, and</li>
41 <li>make it easy to write new tests and add them
42 to an existing test suite.</li>
43 </ul>
44 <p>
45 The intent for the test infrastructure is that it grows
46 along with Batik and keeps monitoring the health of
47 the code base.
48 </p>
49 <p>
50 While the test suites in the infrastructure will be
51 run every day by build/test machines, they are also
52 intended to help the commiters and developers get confident
53 that their code modifications did not introduce regressions.
54 </p>
55
56 <section id="infrastructure">
57 <title>The test infrastructure</title>
58
59 <section>
60 <title>High-level interfaces</title>
61 <p>
62 The following are the high level interfaces in the infrastructure.
63 </p>
64
65 <!-- <div class="figure"><img src="images/testHighLevel.jpg" alt="Batik Viewer"/></div> -->
66
67 <dl class="classes">
68 <dt><a class="class" href="../javadoc/org/apache/batik/test/Test.html">Test</a></dt>
69 <dd>
70 <p>
71 A <code>Test</code> is performing whatever check is needed in its
72 <code>run</code> method, and each run produces a
73 <code>TestReport</code>.
74 </p>
75 </dd>
76 <dt><a class="class" href="../javadoc/org/apache/batik/test/TestReport.html">TestReport</a></dt>
77 <dd>
78 <p>
79 A <code>TestReport</code> describes whether a <code>Test</code>
80 run passed or failed and provides a description of the failure in
81 terms of an error code (unique in the context of a given
82 <code>Test</code>) and a set of key/value pairs.
83 </p>
84 </dd>
85 <dt><a class="class" href="../javadoc/org/apache/batik/test/TestSuite.html">TestSuite</a></dt>
86 <dd>
87 <p>
88 A <code>TestSuite</code> is a test aggregation which can run a set
89 of <code>Test</code> instances.
90 </p>
91 </dd>
92 <dt><a class="class" href="../javadoc/org/apache/batik/test/TestReportProcessor.html">TestReportProcessor</a></dt>
93 <dd>
94 <p>
95 A <code>TestReportProcessor</code> is used to analyze a
96 <code>TestReport</code>. A specific implementation can choose to
97 create graphs, send an email or write an HTML file.
98 </p>
99 </dd>
100 </dl>
101 </section>
102
103 <section>
104 <title>Default implementations</title>
105
106 <p>
107 The test infrastructure comes with a number of default
108 implementations for the interfaces described above.
109 Specifically:
110 </p>
111
112 <dl class="classes">
113 <dt><a class="class" href="../javadoc/org/apache/batik/test/AbstractTest.html">AbstractTest</a></dt>
114 <dd>
115 <p>
116 This implementation of the <code>Test</code> interface is
117 intended to make it easier to write a “safe” <code>Test</code>
118 implementation. See the <a href="#writingNewTests">Writing new
119 tests</a> section for a description of how to use that class.
120 </p>
121 </dd>
122 <dt><a class="class" href="../javadoc/org/apache/batik/test/DefaultTestReport.html">DefaultTestReport</a></dt>
123 <dd>
124 <p>
125 This class provides a simple implementation of the
126 <code>TestReport</code> interface that most <code>Test</code>
127 implementations will be able to use. See the
128 <a href="#writingNewTests">Writing new tests</a> section for
129 more details.
130 </p>
131 </dd>
132 <dt><a class="class" href="../javadoc/org/apache/batik/test/DefaultTestSuite.html">DefaultTestSuite</a></dt>
133 <dd>
134 <p>
135 This class provides an implementation of the
136 <code>TestSuite</code> interface and makes it
137 easy to aggregate <code>Test</code> instances.
138 </p>
139 </dd>
140 <dt><a class="class" href="../javadoc/org/apache/batik/test/SimpleTestReportProcessor.html">SimpleTestReportProcessor</a></dt>
141 <dd>
142 <p>
143 This class is a sample <code>TestReportProcessor</code>
144 implementation that simply traces the content of a
145 <code>TestReport</code> to an output stream.
146 </p>
147 </dd>
148 <dt><a class="class" href="../javadoc/org/apache/batik/test/TestReportMailer.html">TestReportMailer</a></dt>
149 <dd>
150 <p>
151 This is another implementation of the
152 <code>TestReportProcessor</code> interface that emails a test
153 report to a list of destination e-mail addresses.
154 </p>
155 </dd>
156 </dl>
157 </section>
158
159 <section>
160 <title>XML implementations</title>
161
162 <p>
163 The test infrastructure is using XML-out (and XML-in
164 too, see the <a href="#runningATestSuite">Running a test suite</a>
165 section) as a favorite way to generate test reports. The
166 <a class="class" href="../javadoc/org/apache/batik/test/XMLTestReportProcessor.html">XMLTestReportProcessor</a>
167 implementation of the <code>TestReportProcessor</code> interface.
168 It outputs reports in XML in a configurable directory.
169 </p>
170 <p>
171 The <code>XMLTestReportProcessor</code> can notify an
172 <a class="class" href="../javadoc/org/apache/batik/test/XMLReportConsumer.html">XMLReportConsumer</a>
173 when it has created a new report. There is one implementation of
174 that interface that can run an XSL stylesheet on the
175 XML report (e.g., to generate an HTML report), called
176 <a class="class" href="../javadoc/org/apache/batik/test/XSLXMLReportConsumer.html">XSLXMLReportConsumer</a>.
177 This is used by the <code>regard</code> rule in the Batik build to produce an
178 HTML report for the default regression test suite.
179 </p>
180 </section>
181 </section>
182
183 <section id="managingATestSuite">
184 <title>Managing test suites</title>
185
186 <p>
187 The infrastructure is designed to make it easy to create, update
188 and modify test suites. This section describes how to describe a
189 set of tests to be run and how to actually run that test suite.
190 </p>
191
192 <section>
193 <title>Describing a test suite</title>
194 <p>
195 Test suites can be described in XML (XML-in refered to earlier
196 in this document). The general format for describing a test suite is:
197 </p>
198 <source><![CDATA[<testSuite id="testSuiteA" name="MyFavoriteTestSuite">
199 <!-- Set of tests to be run -->
200 <test id="t1" class="myFavoriteTestClassA"/>
201 <test id="t2" class="myFavoriteTestClassB"/>
202 <test id="t3" class="myFavoriteTestClassC"/>
203 </testSuite>]]></source>
204
205 <p>
206 Note that tests can be grouped in <code>testGroup</code> elements,
207 which can have their own <code>id</code> and <code>class</code>
208 attributes. This is useful because it allows developers to run
209 specific tests or test groups by specifying their IDs. In addition,
210 because the class attribute is inherited by a <code>test</code> element
211 from its parent, <code>testGroup</code>s allow the developers to
212 group tests which use the same class and specify that class on the
213 group.
214 </p>
215
216 <p>
217 <code>Test</code> instances listed in a test suite can have arguments
218 passed to them, as defined by the test class. These arguments are
219 passed in using <code>arg</code> child elements.
220 </p>
221
222 <p>
223 The following example shows a test suite with two tests:
224 </p>
225
226 <source><![CDATA[<testSuite id="sampleTestSuite" name="SAMPLE TEST SUITE">
227
228 <!-- ========================================================================== -->
229 <!-- Validates that the SVGRenderingAccuracyTest class is operating as expected -->
230 <!-- ========================================================================== -->
231 <test id="renderingAccuracyTest" class="org.apache.batik.test.svg.SVGRenderingAccuracyTestValidator"/>
232
233 <!-- ========================================================================== -->
234 <!-- Rendering regression tests -->
235 <!-- ========================================================================== -->
236 <test id="anne.svg" class="org.apache.batik.test.svg.SVGRenderingAccuracyTest">
237 <arg class="java.net.URL"
238 value="file:samples/anne.svg"/>
239 <arg class="java.net.URL"
240 value="file:test-references/samples/solaris/anne.png"/>
241 <property name="VariationURL"
242 class="java.net.URL"
243 value="file:test-references/samples/variation/anne.png"/>
244 <property name="SaveVariation"
245 class="java.io.File"
246 value="test-references/samples/variation-candidate/anne.png"/>
247 </test>
248
249 </testSuite>]]></source>
250 </section>
251
252 <section id="runningATestSuite">
253 <title>Running a test suite</title>
254
255 <p>
256 Yet another XML file describes which test to run and how to process
257 the generated test reports. The general syntax is something
258 like:
259 </p>
260 <source><![CDATA[<testRun id="regard" name="Test Run Name Here">
261
262 <!-- =================================== -->
263 <!-- Descriptions of processors that -->
264 <!-- will process the results of the -->
265 <!-- test suite -->
266 <!-- =================================== -->
267 <testReportProcessor class="myFavoriteReportProcessorA"/>
268 <testReportProcessor class="myFavoriteReportProcessorB"/>
269
270 <!-- =================================== -->
271 <!-- Set of test suite to run. They will -->
272 <!-- produce TestReports. -->
273 <!-- =================================== -->
274 <testSuite href="http://url.to.my.first.test.suite"/>
275 <testSuite href="http://url.to.my.second.test.suite"/>
276
277 </testRun>]]></source>
278
279 <p>
280 <code>testRun</code> elements can be nested. In a nutshell, you can
281 specify a set of <code>TestReportProcessor</code>s which should
282 process the <code>TestReport</code> generated by the
283 <code>TestSuite</code> built from the list of <code>Test</code>
284 instances described in the files referenced by the
285 <code>testSuite</code> elements.
286 </p>
287 <p>
288 For example:
289 </p>
290 <source><![CDATA[<testRun name="Batik Standard Regression Test Run">
291
292 <testRun name="REGARD">
293 <testReportProcessor class="org.apache.batik.test.xml.XMLTestReportProcessor">
294 <arg class="org.apache.batik.test.xml.XSLXMLReportConsumer">
295 <!-- Stylesheet -->
296 <arg class="java.lang.String" value="file:test-resources/org/apache/batik/test/svg/HTMLReport.xsl"/>
297 <!-- Ouput Directory -->
298 <arg class="java.lang.String" value="test-reports/html"/>
299 <!-- Output file prefix -->
300 <arg class="java.lang.String" value="RegardResult"/>
301 <!-- Output file suffix -->
302 <arg class="java.lang.String" value=".html"/>
303 </arg>
304 </testReportProcessor>
305
306 <testSuite href="file:test-resources/org/apache/batik/test/samplesRendering.xml"/>
307 <testSuite href="file:test-resources/org/apache/batik/svggen/regsvggen.xml"/>
308 <testSuite href="file:test-resources/org/apache/batik/test/unitTesting.xml"/>
309 </testRun>
310
311 </testRun>]]></source>
312
313 <p>
314 There is a rule in Batik's <code>build.xml</code> file to run a test
315 suite defined in an XML file as the one above. At the command line,
316 type the following, for Windows:
317 </p>
318 <source>build runtestsuite path/to/my/newly/created/testSuite.xml</source>
319 <p>
320 and for Unix:
321 </p>
322 <source>build.sh runtestsuite path/to/my/newly/created/testSuite.xml</source>
323 <p>
324 In addition, the <code>regard</code> rule runs a specific set of
325 tests by default, so that you do not need to pass any
326 <em>testRun</em> file argument.
327 </p>
328 <p>
329 <strong><code>regard</code> is the project’s safeguard against
330 regressions</strong>.</p>
331 </section>
332 </section>
333
334 <section id="regard">
335 <title>regard: the Batik regression test suite</title>
336
337 <p>
338 The regard test suite contains all the regression tests for the Batik
339 project. The <code>regard</code> tool is a specific test suite
340 description, <code>regard.xml</code> (which you can find in the
341 <code>test-resources/org/apache/batik/test</code> directory). That
342 file contains a set of test suite files which sould be run.
343 </p>
344
345 <p>
346 The following describes how to use the regard tool and some of the
347 most important tests in the regard test suite.
348 </p>
349
350 <section>
351 <title>Running regard</title>
352
353 <p>
354 The regard tool lets you run either all the tests or any specific
355 test you want in the test suite. To run all the tests in the regard
356 test suite, type the following at the command line, for Windows:
357 </p>
358
359 <source>build regard</source>
360 <p>
361 and for Unix:
362 </p>
363 <source>build.sh regard</source>
364
365 <p>
366 To run a specific test in the test suite, type the qualified test ID
367 or any substring of that ID:
368 </p>
369
370 <source>build.sh regard <em>id-list</em></source>
371
372 <p>For example:</p>
373 <source>build.sh regard unitTesting.ts batikFX.svg</source>
374
375 <p>
376 will run all the tests with an ID containing
377 <code>unitTesting.ts</code> (i.e., all the test selection unit
378 testing, see
379 <code>test-resources/org/apache/batik/gvt/unitTesting.xml</code>)
380 and the accuracy rendering test on <code>batikFX.svg</code> (because
381 it is the only test with <code>batikFX.svg</code> in its ID).
382 </p>
383 </section>
384
385 <section>
386 <title>Rendering accuracy tests</title>
387
388 <p>
389 There is a <code>Test</code> implementation,
390 <a class="class" href="../javadoc/org/apache/batik/test/SVGRenderingAccuracyTest.html">SVGRenderingAccuracyTest</a>,
391 which checks that Batik’s rendering of an SVG document stays accurate.
392 It compares reference images with the rendering Batik produces and
393 reports any discrepancy.
394 </p>
395
396 <p>
397 An <code>SVGRenderingAccuracyTest</code>’s constructor configuration
398 is made of:
399 </p>
400 <ul>
401 <li>the URL to the SVG it should render, and</li>
402 <li>the URL to a reference PNG file.</li>
403 </ul>
404
405 <p>
406 The default behavior for the test is to render the SVG into a PNG
407 file and compare with the reference image. If there is no
408 difference, the test passes. Otherwise, it fails.
409 </p>
410
411 <p>
412 In addition to this default behavior, the
413 <code>SVGRenderingAccuracyTest</code> can take an optional
414 configuration parameter, an image URL defined as an “accepted”
415 variation around the reference image. If such a variation image is
416 specified, then the test will pass if:
417 </p>
418 <ul>
419 <li>the rasterized SVG is equal to the reference image, or</li>
420 <li>
421 the difference between the rasterized SVG and the reference image
422 is exactly the same as the accepted variation image.
423 </li>
424 </ul>
425
426 <p>
427 Finally, to ease the process of creating “accepted” variation
428 images, <code>SVGRenderingAccuracyTest</code> can take an optional
429 file name (called <code>saveVariation</code>) describing where the
430 variation between the rasterized SVG and the reference image will be
431 stored in case the rasterized SVG is different from the reference
432 image and the difference is not equal to the variation image, if any
433 was defined. That way, it becomes possible to run a test, and if that
434 test fails, the developer can review the <code>saveVariation</code>
435 image and decide whether it is an acceptable variation or not and
436 use it in subsequent test run as the “accepted” variation image, which
437 will allow the test to pass if that exact same variation remains
438 constant.
439 </p>
440 </section>
441
442 <section>
443 <title>Day to day use of regard</title>
444
445 <section>
446 <title>Initial set up</title>
447 <p>
448 To set up the test environment the first time, you need to:
449 </p>
450 <ul>
451 <li>
452 check out the latest version of the code, including the
453 <code>test-</code>* directories (sources, resources and
454 references) and the <code>build.xml</code> file, and
455 </li>
456 <li>
457 run the regard test suite once:
458 <source>build regard</source>
459 </li>
460 </ul>
461 <p>
462 This will generate an HTML test report (<code>report.html</code>)
463 in the
464 <code>test-reports/<em>yyyy</em>.<em>mm</em>.<em>dd</em>-<em>HHhMMmSSs</em>/html</code>
465 directory. Depending on how much different text rendering is
466 between your work environment and the environment used to create
467 the reference images, you will get more or less test that will
468 fail, because of differences in the way text is rendered on various
469 platforms and because of fonts not being available on some
470 platforms. For example, a running the test on a Windows 2000
471 laptop against images generated on the Solaris platform caused 16
472 tests out of 71 to fail.
473 </p>
474 <p>
475 Review the HTML report to make sure that the differences are
476 really due to text variations. This will usually be the case and
477 you can make sure by clicking on the diff images contained in the
478 report to see them at full scale. You can you can then turn the
479 “candidate” variations generated by the test into “accepted”
480 variations by moving files from one directory to another:
481 </p>
482 <source>mv test-references/samples/candidate-variations/*.png test-references/samples/accepted-variations/*.png
483 mv test-references/samples/tests/candidate-variations/*.png test-references/samples/tests/accepted-variations/*.png</source>
484 <p>You can now run the test again:</p>
485 <source>build regard</source>
486 <p>
487 Check the newly generated HTML report in the
488 <code>test-reports/html</code> directory: there should no
489 longer be any test failure.
490 </p>
491 </section>
492
493 <section>
494 <title>Daily usage</title>
495
496 <p>
497 Once the intial set up has been done, you can use regard by simply
498 updating your SVN copy, including the test-references. If no
499 change occurs, your test will keep passing with your reference
500 images. If a test fails (e.g., if someone checks in a new reference
501 image from a platform different than the one you are using, you
502 will have to check if it is because of system specific reasons or
503 if there is a bigger problem.
504 </p>
505 </section>
506 </section>
507
508 <section>
509 <title>SVG generator tests</title>
510
511 <p>
512 Regard contains over 100 tests for checking regressions on the SVG
513 generator. If you use <code>svggen</code> as an argument to regard,
514 all the SVG generator tests will be run (because
515 <code>regard.xml</code> points to
516 <code>test-resources/org/apache/batik/svggen/regsvggen.xml</code>,
517 which is a test suite description for the SVG generator and that
518 file’s root <code>testSuite</code> element has the “svggen” ID).
519 </p>
520 </section>
521 </section>
522
523 <section id="writingNewTests">
524 <title>Writing new tests</title>
525
526 <p>
527 Writing a new test involves either configuring a new test or writing a
528 new <code>Test</code> class. In both cases, you will need to add an
529 entry to a test suite’s XML description. This section uses two test
530 suites as an example: the “regard” test suite to show how to configure
531 a new test and the “unitTests” test suite to show how to add a new
532 <code>Test</code> implementation.
533 </p>
534
535 <section>
536 <title>Adding a new test configuration</title>
537 <p>
538 Imagine that you add a cool new test case to the
539 <code>samples</code> directory, such as
540 <code>linking-viewBox.svg</code>. In order to check for regressions
541 on that file you can add the following entry:
542 </p>
543 <source><![CDATA[ <test id="anne.svg" class="org.apache.batik.test.svg.SVGRenderingAccuracyTest">
544 <arg class="java.net.URL"
545 value="file:samples/tests/linkingViewBox.svg"/>
546 <arg class="java.net.URL"
547 value="file:test-references/samples/tests/solaris/linkingViewBox.png"/>
548 <property name="VariationURL"
549 class="java.net.URL"
550 value="file:test-references/samples/tests/variation/linkingViewBox.png"/>
551 <property name="SaveVariation"
552 class="java.io.File"
553 value="test-references/samples/tests/variation-candidate/linkingViewBox.png"/>
554 </test>]]></source>
555 <p>
556 to the
557 <code>test-resources/org/apache/batik/test/samplesRendering.xml</code>
558 test suite description, the description of the regard test suite. If
559 you have access to the build machine where the reference images are
560 typically generated, you can check on the reference image in
561 <code>test-references/samples/tests</code>. Otherwise (and this is
562 OK), you can let the test fail the first time it is run on the
563 build/test machine and that will be a reminder for whoever is
564 responsible for that machine that a valid reference image should be
565 checked in.
566 </p>
567 </section>
568
569 <section>
570 <title>Writing a new test</title>
571
572 <p>
573 Imagine you want to validate some aspect of your code, and let's take
574 the bridge error handling as an example. You could create a new
575 class in the <code>test-sources</code> directory, in
576 <code>test-sources/org/apache/batik/bridge</code> in our example,
577 and let's call it <code>ErrorHandlingTest</code>. To simplify the
578 implementation of the <code>Test</code> interface, you can choose
579 to derive from the <code>AbstractTest</code> class and generate a
580 <code>DefaultTestReport</code>.
581 </p>
582
583 <p>
584 While writing the <code>Test</code> you may want to use your own XML
585 file with just your test, for example:
586 </p>
587 <source><![CDATA[ <testReportProcessor class="org.apache.batik.test.SimpleTestReportProcessor"/>
588
589 <test class="org.apache.batik.bridge.ErrorHandlingTest">
590 <!-- Expected error code -->
591 <arg class="java.lang.String" value="expected.error.code"/>
592 <!-- Input SVG that this test manipulates to generate error conditions -->
593 <arg class="java.net.URL" value="file:test-resources/org/apache/batik/bridge/ErrorHandlingBase.svg"/>
594 <!-- Id of the element to test -->
595 <arg class="java.lang.String value="rectangle6"/>
596 <!-- Attribute to test -->
597 <arg class="java.lang.String value="x"/>
598 <!-- Value to test on the attribute -->
599 <arg class="java.lang.String value="abcd"/>
600 </test>]]></source>
601 <p>
602 This is just an example and does not pretend to be the right way to go
603 about implementing or specifying this specific type of test. Once done
604 with tuning the test, one or multiple configurations for the test can
605 be added to the relevant test suite’s XML description. In some cases,
606 it will be interesting to create a separate test suite.
607 </p>
608 </section>
609
610 </section>
611
612 </body>
613
614 </document>