com.clarkware.junitperf

## Class TestFactory

- java.lang.Object
- - com.clarkware.junitperf.TestFactory

Direct Known Subclasses:
  TestMethodFactory

    public class TestFactory
    extends java.lang.Object

The `TestFactory` class creates thread-local `TestSuite` instances.

This factory class should be used in cases when a stateful test is intended to be decorated by a `LoadTest`. A stateful test is defined as any test that defines test-specific state in its `setUp()` method.

Use of the `TestFactory` ensures that each thread spawned by a `LoadTest` contains its own `TestSuite` instance containing all tests defined in the specified `TestCase` class.

A typical usage scenario is as follows:

>      Test factory = new TestFactory(YourTestCase.class);
>      LoadTest test = new LoadTest(factory, numberOfUsers, ...);
>      ...

Of course, static variables cannot be protected externally, so tests intended to be run in a multi-threaded environment should ensure that the use of static variables is thread-safe.

This class is dependent on Java 2. For earlier platforms a local cache implementation should be changed to use, for example, a HashMap to track thread-local information.

Author:
  Mike Clark, Clarkware Consulting, Inc., Ervin Varga
See Also:
  `LoadTest`

### Field Summary

Fields
`protected java.lang.Class` `testClass`

### Constructor Summary

Constructors
Constructor and Description
`TestFactory(java.lang.Class testClass)` Constructs a `TestFactory` instance.

### Method Summary

Methods
`int` `countTestCases()` Returns the number of tests in this test.
`protected Test` `getTest()`
`protected TestSuite` `getTestSuite()`
`protected TestSuite` `makeTestSuite()`
`void` `run(TestResult result)` Runs an instance of the `Test` class and collects its result in the specified `TestResult`.
`java.lang.String` `toString()` Returns the test description.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### testClass

    protected final java.lang.Class testClass

### Constructor Detail

#### TestFactory

    public TestFactory(java.lang.Class testClass)

Constructs a `TestFactory` instance.

Parameters:
  `testClass` - The `TestCase` class to load test.

### Method Detail

#### run

    public void run(TestResult result)

Runs an instance of the `Test` class and collects its result in the specified `TestResult`.

Each invocation of this method triggers the creation of a new `Test` class instance as specified in the construction of this `TestFactory`.

Parameters:
  `result` - Test result.

#### countTestCases

    public int countTestCases()

Returns the number of tests in this test.

Returns:
  Number of tests.

#### toString

    public java.lang.String toString()

Returns the test description.

Overrides:
  `toString` in class `java.lang.Object`
Returns:
  Description.

#### getTest

    protected Test getTest()

#### getTestSuite

    protected TestSuite getTestSuite()

#### makeTestSuite

    protected TestSuite makeTestSuite()