![]() |
|
Sponsored Link •
|
Advertisement
|
Artima Testkit is an API and application that can help you build and run unit and conformance
tests. The main concepts of the API are represented by the types Suite
, Reporter
,
and Runner
. You define test methods in subclasses of Suite
. You use
Reporter
s to present test results. And you use
Runner
to run the suites. Runner
uses recipe files, which contain
settings that describe how to perform a particular run.
You can create recipe files for later reuse, to share among the members of a team, or to distribute
to the public as part of a conformance test kit.
The Artima Testkit API is designed to give client programmers much room to customize its behavior.
For example, the contracts of the classes and interfaces in the Artima Testkit API use the words "test" and "suite"
generically to allow subclasses and implementation classes maximum flexibility. A com.artima.testkit.Suite
is one kind of suite. A test method in a com.artima.testkit.Suite
subclass is one kind of test. But you
can define other kinds of suites
and tests if you wish. For example, JUnitSuite
, a package-access subclass of Suite
in the com.artima.testkit
package, defines a "test" as a test method in a JUnit test case.
Aside from just declaring test methods in your Suite
subclasses, you can
override many methods declared in Suite
. Of particularly usefulness is overriding
executeTestMethods
, executeSubSuites
, or execute
itself.
For example, JUnitSuite
overrides execute
so that it runs a suite of JUnit test cases. JUnitSuite
overrides getTestCount
so that it returns the expected number of JUnit test cases to be run. Some other ideas for
subclassing Suite
are:
DirectoryDiscoverySuite
that discovers Suite
subclasses whose class files are sitting in a specified directory or any of its subdirectories.
execute
to fire off multi-threaded tests.
execute
to perform any preparation before running an entire suite of
tests, or cleanup afterwards
executeTestMethods
so that the discovered test methods are called
in a particular order.
Testkit comes with several reporters built in:
a graphical reporter that presents test results via a graphical user interface; a print reporter that writes
results to the standard output, standard error,
or a file; and a dispatch reporter that forwards results to multiple reporters.
You can make your own reporters to customize the way test results
are presented simply by creating classes that implement
Reporter
.
Some ideas for custom reporters are:
For example, if as part of your nightly build process you automatically run a full test suite on your
software, you could define Reporter
s that email a summary
of the results each night to team members and place detailed results on a set of web pages.
Most Reporter
methods take a single parameter of type Report
.
Report
includes many pieces of information, such as a Thread
that
can help you understand multi-threaded tests.
If you wish to pass more information than you can with a standard Report
, you
can create a subclass of Report
that has extra
information. You can then override any of the execute
, executeTestMethods
,
or executeSubSuites
methods, and create test methods in your Suite
subclasses. These methods can fire instances of your Report
subclass
which include the extra information you desire to have reported.
You can then
create custom Reporter
s that downcast the Report
to your new
Report
subclass, extract the extra information, and report it to the user.
Artima Testkit is to a great extent JUnit refactored.
If you have existing JUnit tests, you can use Artima Testkit to run them.
In JUnit, runners are a separate concept from the framework API. The JUnit distribution
includes three runners: a text runner, which write test results to the standard output;
an AWT runner, which presents test results via an AWT graphical user interface; and a Swing runner,
which presents test results via a Swing graphical user interface.
One way to think of Artima Testkit, therefore, is simply as another JUnit runner. Using Artima Testkit to
run your JUnit tests allows you to enjoy features not
present in the three standard JUnit runners, such as recipes, reporters, runpaths, and full stack traces in reported results.
Sponsored Links
|