First, read the document

       "JUnit best practices: Techniques for building resilient,
       relocatable, multithreaded JUnit tests"
       by Andy Schneider

       JavaWorld
       December 2000

       http://www.javaworld.com/javaworld/jw-12-2000/jw-1221-junit_p.html

       local copy in ./jw-1221-junit_p.html

    We make use of (slightly modified) versions of their utility
    classes

Now, to make a unit test for class Foo
(1) Copy the template unit test file utils/junit/TestEmpty.java to 
    FooUnit.java

    NOTE: If you are doing a multi-threaded test, use
    TestEmptyMultiThreaded.java as your template instead

(2) Modify FooUnit

      o replace string "TestEmpty" (or "TestEmptyMultiThreaded") with
        string "FooUnit" throughout the file (this changes the class
        name, constructor, suite constructor, and command line text
        output)

      o Delete the inner class "InnerFooUnit" unless you need it

      o OPTIONAL: Modify setUp() and tearDown(). See below.

      o Rename the method "testX" by replacing "X" with some 
        informative name (e.g., "testAssignmentIntegrity")

        NOTE: A failed test *must* either call fail() or call one of
        the assert() functions (assertTrue(...), assert(...),
        assertFalse(...)). The code *must not* call exit() (as some of
        our current tests do).

	NOTE: The method name *must* begin with the string "test" for
	every method you want run by junit

	NOTE: See below for how to modify testX for
	TestEmptyMultiThreaded

      o OPTIONAL: Create additional "testY", "testZ", etc. functions
        for junit to run

(3) Run unit tests
 
      o Run all unit tests: make junit 

        Notice that by conforming to the templates listed above, you
        ensure that your new test is automatically included when we
        run TestAll.java

      o Run just Foo's unit test: make FooUnit.junit

      o Run all unit tests with text UI (rather than gui): make junittext

(4) fix the Makefile to remove reference to old selftest

    If you are migrating an old test to a new one, replace the line 
    in unit: to run to FooUnit rather than Foo

    E.g., the line
         $(JAVA) -ea -classpath $(CLASSPATH) WorkQueue; \

    became
         $(JAVA) -ea -classpath $(CLASSPATH) WorkQueueUnit; \


ADDITIONAL DETAILS

(1) Fixtures

  The OPTIONAL step of modifying setUp and tearDown allows you to
  create fixtures. The basic idea is that if you have a bunch of tests
  that each require an environment around them, you can define how to
  create (destroy) that environment in setUp (tearDown) and junit will
  make sure that the environment is created before each individual
  test and destroyed after each individual test

(2) Multi-threaded tests

  The template TestEmptyMultiThreaded provides a structure for running
  multi-threaded tests that ensures that exceptions are caught
  appropriately when threads encounter problems.

  To use it, 
  
  (a) Create worker thread inner classes by overriding TestWorker1,
      TestWorker2, etc.
 
      Note: These worker thread classes must be defined within the
      TestFooMultiThreaded class. E.g., their code must appear inside
      the first and last brackets of the enclosing class. Otherwise
      you get a copiler error

      The main difference between these runnables and a "normal"
      thread class is that the "main" code is in runTestCase() rather
      than in run(). The parent class TestCaseRunnable has the run()
      method, which then calls runTestCase().

  (b) In your testX test case, create an array of worker threads and
      pass that array to runTestCaseRunnables()

 
