Class TestFactory
- java.lang.Object
-
- com.clarkware.junitperf.TestFactory
-
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
TestMethodFactory
public class TestFactory extends java.lang.Object implements junit.framework.TestTheTestFactoryclass creates thread-localTestSuiteinstances.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 itssetUp()method.Use of the
TestFactoryensures that each thread spawned by aLoadTestcontains its ownTestSuiteinstance containing all tests defined in the specifiedTestCaseclass.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 Modifier and Type Field Description protected java.lang.ClasstestClass
-
Constructor Summary
Constructors Constructor Description TestFactory(java.lang.Class testClass)Constructs aTestFactoryinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcountTestCases()Returns the number of tests in this test.protected junit.framework.TestgetTest()protected junit.framework.TestSuitegetTestSuite()protected junit.framework.TestSuitemakeTestSuite()voidrun(junit.framework.TestResult result)Runs an instance of theTestclass and collects its result in the specifiedTestResult.java.lang.StringtoString()Returns the test description.
-
-
-
Method Detail
-
run
public void run(junit.framework.TestResult result)
Runs an instance of theTestclass and collects its result in the specifiedTestResult.Each invocation of this method triggers the creation of a new
Testclass instance as specified in the construction of thisTestFactory.- Specified by:
runin interfacejunit.framework.Test- Parameters:
result- Test result.
-
countTestCases
public int countTestCases()
Returns the number of tests in this test.- Specified by:
countTestCasesin interfacejunit.framework.Test- Returns:
- Number of tests.
-
toString
public java.lang.String toString()
Returns the test description.- Overrides:
toStringin classjava.lang.Object- Returns:
- Description.
-
getTest
protected junit.framework.Test getTest()
-
getTestSuite
protected junit.framework.TestSuite getTestSuite()
-
makeTestSuite
protected junit.framework.TestSuite makeTestSuite()
-
-