|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.apache.qpid.junit.extensions.AsymptoticTestCase
public class AsymptoticTestCase
AsymptoticTestCase is an extension of TestCase for writing unit tests to analyze asymptotic time and space behaviour.
ParameterizedTestCases allow tests to be defined which have test methods that take a single int argument. Normal JUnit test methods do not take any arguments. This int argument can be interpreted in any way by the test but it is intended to denote the 'size' of the test to be run. For example, when testing the performance of a data structure for different numbers of data elements held in the data structure the int parameter should be interpreted as the number of elements. Test timings for different numbers of elements can then be captured and the asymptotic behaviour of the data structure with respect to time analyzed. Any non-parameterized tests defined in extensions of this class will also be run.
TestCases derived from this class may also define tear down methods to clean up their memory usage. This is intended to be used in conjunction with memory listeners that report the amount of memory a test uses. The idea is to write a test that allocates memory in the main test method in such a way that it leaves that memory still allocated at the end of the test. The amount of memory used can then be measured before calling the tear down method to clean it up. In the data structure example above, a test will allocate as many elements as are requested by the int parameter and deallocate them in the tear down method. In this way memory readings for different numbers of elements can be captured and the asymptotic behaviour of the data structure with respect to space analyzed.
Responsibilities | Collaborations |
---|---|
Store the current int parameter value. | TKTestResult and see AsymptoticTestDecorator too.
|
Invoke parameterized test methods. |
TKTestResult
or
AsymptoticTestDecorator
rather than this class. This would mean that tests don't have to extend this
class to do time and space performance analysis, these methods could be added to any JUnit TestCase class
instead. This would be an improvement because existing unit tests wouldn't have to extend a different class to
work with this extension, and also tests that extend other junit extension classes could have parameterized
and tear down methods too.Field Summary | |
---|---|
(package private) ThreadLocal<org.apache.qpid.junit.extensions.AsymptoticTestCase.TestMeasurements> |
threadLocalMeasurement
Thread local for holding measurements on a per thread basis. |
Constructor Summary | |
---|---|
AsymptoticTestCase(String name)
Constructs a test case with the given name. |
Method Summary | |
---|---|
int |
getN()
Gets the current value of the integer parameter to be passed to the parameterized test. |
long |
getTestEndMemory()
Reports the memory usage at the end of the test. |
long |
getTestStartMemory()
Reports the memory usage at the start of the test. |
long |
getTestTime()
Reports how long the test took to run. |
void |
reset()
Resets the instrumentation values to zero, and nulls any references to held measurements so that the memory can be reclaimed. |
protected void |
runTest()
Runs the test method for this test case. |
void |
setN(int n)
Sets the current value of the integer parameter to be passed to the parameterized test. |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runBare, setName, setUp, tearDown, toString |
Methods inherited from class junit.framework.Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface junit.framework.Test |
---|
countTestCases, run |
Field Detail |
---|
ThreadLocal<org.apache.qpid.junit.extensions.AsymptoticTestCase.TestMeasurements> threadLocalMeasurement
Constructor Detail |
---|
public AsymptoticTestCase(String name)
name
- The name of the test.Method Detail |
---|
public int getN()
public void setN(int n)
n
- The new current value of the integer parameter.public long getTestTime()
getTestTime
in interface InstrumentedTest
public long getTestStartMemory()
getTestStartMemory
in interface InstrumentedTest
public long getTestEndMemory()
getTestEndMemory
in interface InstrumentedTest
public void reset()
reset
in interface InstrumentedTest
protected void runTest() throws Throwable
runTest
in class junit.framework.TestCase
Throwable
- Any Throwables from the test methods invoked are allowed to fall through.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |