|
|
|
Artima SuiteRunner |
Why |
Getting Started |
Tutorial |
Get Help |
Discuss |
Print |
Email |
First Page |
Previous |
Next
|
|
Advertisement
|
Summary
In this tutorial, Bill Venners shows you how to create a custom reporter for Artima SuiteRunner that formats unit test results in XML.
Artima SuiteRunner is a free open source testing toolkit for Java released under the Open Software License. You can use this tool with JUnit to run existing JUnit test suites, or standalone to create unit and conformance tests for Java APIs.
One advantage of using Artima SuiteRunner to run your JUnit tests is Artima SuiteRunner's reporter architecture.
A reporter is an object that collects test results and presents them in some way to users. Artima SuiteRunner
includes several build-in configurable reporters that can write to the standard error and output streams, files,
and a graphical user interface. But Artima SuiteRunner also supports custom reporters. If you want to present results
of tests in a different way, such as HTML, email, database, or log files, you can create your own custom reporter
that presents results in those ways. This tutorial will show you how to create a custom reporter, using as an example
a custom reporter named com.artima.examples.reporter.xml.ex1.XMLReporter (XMLReporter)
that formats test results in XML.
Class XMLReporter was added to the Artima SuiteRunner distribution zip file in version 1.0beta5. If you have a release
prior to 1.0beta5, please download the
latest version of Artima SuiteRunner. Once you unzip the distribution ZIP file, you'll find the source code
for XMLReporter in the suiterunner-[release]/example/com/artima/examples/reporter/xml/ex1 directory.
You can also view the complete listing in HTML. Because XMLReporter.java is released
under the Open Software License, you can use it as a template when creating your own custom Reporter.
Reporter's Event Handler Methods
To create a custom reporter, you create a class that implements interface org.suiterunner.Reporter (Reporter).
Interface Reporter declares 13 methods: a setConfiguration method, a dispose method,
and 11 event handler methods. In your custom Reporter, you must of course implement all 13 of these methods.
As tests run, the 11 event handler methods are notified of events such as
test starting, test succeeded, and test failed.
The event handler methods determine how your Reporter
will present test results to the user. For example, if you want to present test results as HTML, you write event handler methods that
produce HTML. Or, if you want to store test results in a database, you write event handler methods that insert records into that database.
In this article, I will show you an XMLReporter whose
event handler methods write XML to the standard output.
Figure 1 shows all 11 event handler methods and their meanings.
Figure 1. Reporter's Event Handler Methods
org.suiterunnerReporter
|
public interface Reporter Interface implemented by classes whose instances collect the results of a running suite of tests and presents those results in some way to the user. |
| Methods |
public void infoProvided(Report report)Provides information that is not appropriate to report via any other Reporter method.
|
public void runAborted(Report report)Indicates a runner encountered an error while attempting to run a suite of tests. |
public void runCompleted()Indicates a runner has completed running a suite of tests. |
public void runStarting(int testCount)Indicates a runner is about run a suite of tests. |
public void runStopped()Indicates a runner has stopped running a suite of tests prior to completion, likely because of a stop request. |
public void suiteAborted(Report report)Indicates the execution of a suite of tests has aborted, likely because of an error, prior to completion. |
public void suiteCompleted(Report report)Indicates a suite of tests has completed executing. |
public void suiteStarting(Report report)Indicates a suite of tests is about to start executing. |
public void testFailed(Report report)Indicates a suite (or other entity) has completed running a test that failed. |
public void testStarting(Report report)Indicates a suite (or other entity) is about to start a test. |
public void testSucceeded(Report report)Indicates a suite (or other entity) has completed running a test that succeeded. |
|
Sponsored Links
|