Project Contributors
Motivation
Writing unit tests is a mundane task that software developers
generally fear. The purpose of this project is to provide a
framework that will make developing unit tests more of an
engineering activity.
The well-documented failing of JUnit is the lack of separation
between test data definition and test code. In normal JUnit
practice, the notion of a test case is ill-defined. Indeed, a test
case in JUnit is truely a suite of test cases for a specific
method.
JSpecUnit resolves both of these issues. Test code is written in a
generic fashion, and the specific data for a test is placed in an
XML file. Furthermore, the structure of this XML file allows for
the definition of suites of identifiable test cases per method.
Related Work
JSpecUnit was inspired by JTestCase. JTestCase
shares a similar motivation of test-data/test-code
separation. JSpecUnit makes two improvements on JTestCase, which
merit the definition of a new project :
Improved XML Schema
The XML Schema for JTestCase is too closely linked to JUnit. While
this has some advantages, it has the disadvantage of
lack-of-modularity. In JSpecUnit, the XML schema attempts to
capture the concept of test cases independently of how they are
executed. There is still a Java dependency, in the sense that test
cases are structed in XML along package/class/method lines.
Test Harness
JSpecUnit provides a test harness that can be used to run suites
of tests. This harness improves on the normal JUnit test runner in
its use of the XML data to determine which test cases to run. This
means that the test suites are more precise than JUnit suites, and
are more independent of the test code.
Design Overview
There are extensive Javadocs provided with the project. These give
a fairly good idea of what the individual classes do. Here, a
quick overview of the design is provided.
The key notion in JSpecUnit is that of a
UnitTestSpecification. There is a class corresponding to this
conceptual notion, jspecunit.data.UnitTestSpecification. A
UnitTestSpecification describes the test input, and the expected
outcome of the test case.
JSpecUnit provides a wrapper around the JUnit TestCase class that
test developers can subclass. This wrapper provides some helper
methods, but most importantly provides access to a
UnitTestSpecification. With this object in hand, test developers
can write generic test code based on the names of the
parameters defined in the UnitTestSpecification.
The other key offering of JSpecUnit is the UnitHarness
object. A UnitHarness provides a means to execute a suite of test
cases specified by UnitTestSpecification objects.
Examples
In the cvs repository, there are some examples of code, test-code,
and test-specifications. They are placed under the examples
directory.
There is also a brief tutorial available.
Future Work
The current release (v0.1) of JSpecUnit is quite rudimentary,
although it is quite an improvement over standard JUnit. There are
many areas in which JSpecUnit can become a more useful tool. A
framework for specifying complex user-defined Java types in XML
would be extremely useful to integrate with JSpecUnit, and would
save a lot of mundane lines of test code. Already, some people have
suggested enhancements to the XML schema which are quite
pertinent. For example, a test method may specify a pattern
for parameters, with a test case specifying merely the values for
the parameters.
Acknowledgements
Software is never developed in a vacuum. The design for this
project was discussed at length with Eytan Faverman, Erik Snowberg,
and Mathieu Gagne.