Package com.objectwave.test

A set of core classes to help with unit testing efforts.


Interface Summary
TestContext The interface that is to provide support to the unit tests.

Class Summary
BatchRunner Recurse from the current user directory and find all .class files that are UnitTest and add to our list of tests.
TestImpl Hide the details of the JUnit test framework.
TestRunner Hide the details of the JUnit test framework.
UnitTestBaseImpl Provide all of the default implementation code.

Package com.objectwave.test Description

A set of core classes to help with unit testing efforts. An abstraction between our code and JUnit. By using this abstraction, users of our libraries are not required to obtain JUnit for their application development needs. Only if you actually run the unit tests does a dependency upon JUnit exist.

The key to using this package is to create test classes that extend com.objectwave.test.UnitTestBaseImpl. A typical unit test declaration looks like the following:

public class Test extends UnitTestBaseImpl
    public static void main( String [] args )
    { new Test(), args );
    public void testSomeBusinessLogic() throws Exception
        boolean value = new MyClass().doSomeWork();
        testContext.assert( "The value is incorrect! ", value);
In the example I have a single test method that will be executed when the TestRunner run's the tests. Any public method that starts with the word 'test' will be invoked by the test runner. To run all my unit tests, I would simply type
java Test
There are some additional features found on UnitTestBaseImpl that should be checked out. The goal is to help you write tests with the LEAST amount of pain as possible. So, just do it.

Stuff relating to the current running tests, such as the ability to do assertions, is abstracted into com.objectwave.test.TestContext. An instance variable within UnitTestBaseImpl contains a reference to an instance of the TestContext and is intended to be used within your tests (as the example shows).
In addition to assertions, TestContext provides the ability to use threads within your unit tests. Hopefully, you can avoid doing this, but sometimes its necessary. When TestContext provides a thread to your runnable, any exceptions or failed assertions will fail the test. It's up to you, the multithreaded programmer, to handle starting, stopping, and any synchronization issues.

Using this framework provides integration with batch test run capability. The class com.objectwave.test.BatchRunner has the ability to walk a directory looking for class files. Each class file it finds is inspected to see if it could be a UnitTestBaseImpl instance. If so, it adds an instance of the class to a list of tests to run in batch mode. Once all tests are discovered, the tests are all executed with a summary of the results displayed at the end.

The intent is to leverage the work being done by the JUnit development communinty, while providing an easy mechanism for us to add additional features necessary for our testing. The additional methods relating to file manipulation in UnitTestBaseImpl are example of our custom extensions, that would likely never make it into the JUnit core code.