|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.qpid.test.framework.listeners.XMLTestListener
public class XMLTestListener
Listens for test results for a named test and outputs these in the standard JUnit XML format to the specified writer.
The API for this listener accepts notifications about different aspects of a tests results through different methods, so some assumption needs to be made as to which test result a notification refers to. For examplestartTest(junit.framework.Test)
will be called, then possibly timing(junit.framework.Test, long, java.lang.Long)
will be called, even though the test instance is
passed in both cases, it is not enough to distinguish a particular run of the test, as the test case instance may
be being shared between multiple threads, or being run a repeated number of times, and can therfore be re-used
between calls. The listeners make the assumption that, for every test, a unique thread will call startTest(junit.framework.Test)
and endTest(junit.framework.Test)
to delimit each test. All calls to set test parameters, timings, state and so on, will occur
between the start and end and will be given with the same thread id as the start and end, so the thread id provides
a unqiue value to identify a particular test run against.
Responsibilities | Collaborations |
---|---|
Listen to test lifecycle notifications. | |
Listen to test errors and failures. | |
Listen to test timings. | |
Listen to test memory usages. | |
Listen to parameterized test parameters. | |
Responsibilities |
Nested Class Summary | |
---|---|
protected static class |
XMLTestListener.Result
Used to capture the results of a particular test run. |
Field Summary | |
---|---|
protected int |
errors
Holds the overall error count. |
protected int |
failures
Holds the overall failure count. |
(package private) List<XMLTestListener.Result> |
results
Holds results for tests that have ended. |
protected int |
runs
Holds the overall tests run count. |
(package private) String |
testClassName
Holds the name of the class that tests are being run for. |
(package private) Map<Long,XMLTestListener.Result> |
threadLocalResults
Map for holding results on a per thread basis as they come in. |
protected Writer |
writer
The results file writer. |
Constructor Summary | |
---|---|
XMLTestListener(Writer writer,
String testClassName)
Creates a new XML results output listener that writes to the specified location. |
Method Summary | |
---|---|
void |
addError(junit.framework.Test test,
Throwable t)
An error occurred. |
void |
addFailure(junit.framework.Test test,
junit.framework.AssertionFailedError t)
A failure occurred. |
void |
addFailure(junit.framework.Test test,
junit.framework.AssertionFailedError e,
Long threadId)
Called when a test completes to mark it as a test fail. |
void |
concurrencyLevel(junit.framework.Test test,
int threads,
Long threadId)
Should be called every time a test completes with the current number of test threads running. |
void |
endBatch(Properties parameters)
Notifies listeners of the end of a complete run of tests. |
void |
endTest(junit.framework.Test test)
Notification that a test ended. |
void |
endTest(junit.framework.Test test,
Long threadId)
Called when a test completes. |
Thread |
getShutdownHook()
Supplies the shutdown hook. |
void |
memoryUsed(junit.framework.Test test,
long memStart,
long memEnd,
Long threadId)
Should be called every time a test completed with the amount of memory used before and after the test was run. |
void |
parameterValue(junit.framework.Test test,
int parameter,
Long threadId)
Should be called every time a parameterized test completed with the int value of its test parameter. |
void |
properties(Properties properties)
Notifies listeners of the tests read/set properties. |
void |
reset(junit.framework.Test test,
Long threadId)
Resets the test results to the default state of time zero, memory usage zero, parameter zero, test passed. |
void |
startBatch()
Notifies listeners of the start of a complete run of tests. |
void |
startTest(junit.framework.Test test)
Notification that a test started. |
void |
timing(junit.framework.Test test,
long nanos,
Long threadId)
Should be called every time a test completes with the run time of that test. |
void |
timing2(junit.framework.Test test,
Long nanos,
Long threadId)
Optionally called every time a test completes with the second timing test. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Writer writer
Map<Long,XMLTestListener.Result> threadLocalResults
List<XMLTestListener.Result> results
protected int errors
protected int failures
protected int runs
String testClassName
Constructor Detail |
---|
public XMLTestListener(Writer writer, String testClassName)
writer
- The location to write results to.testClassName
- The name of the test class to include in the test results.Method Detail |
---|
public void reset(junit.framework.Test test, Long threadId)
reset
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The test to resest any results for.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void startTest(junit.framework.Test test)
startTest
in interface junit.framework.TestListener
test
- The test that started.public void timing(junit.framework.Test test, long nanos, Long threadId)
timing
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The name of the test.nanos
- The run time of the test in nanoseconds.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void timing2(junit.framework.Test test, Long nanos, Long threadId)
timing2
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The name of the test.nanos
- The second timing information of the test in nanoseconds.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void memoryUsed(junit.framework.Test test, long memStart, long memEnd, Long threadId)
memoryUsed
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The test which memory was measured for.memStart
- The total JVM memory used before the test was run.memEnd
- The total JVM memory used after the test was run.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void parameterValue(junit.framework.Test test, int parameter, Long threadId)
parameterValue
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The test which memory was measured for.parameter
- The int parameter value.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void concurrencyLevel(junit.framework.Test test, int threads, Long threadId)
concurrencyLevel
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The test for which the measurement is being generated.threads
- The number of tests being run concurrently.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void properties(Properties properties)
properties
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
properties
- The tests read/set properties.public void endTest(junit.framework.Test test)
endTest
in interface junit.framework.TestListener
test
- The test that ended.public void endTest(junit.framework.Test test, Long threadId)
endTest
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The test which completed.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void addError(junit.framework.Test test, Throwable t)
addError
in interface junit.framework.TestListener
test
- The test in which the error occurred.t
- The throwable that resulted from the error.public void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError t)
addFailure
in interface junit.framework.TestListener
test
- The test in which the failure occurred.t
- The JUnit assertions that led to the failure.public void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError e, Long threadId)
addFailure
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
test
- The test which failed.e
- The assertion that failed the test.threadId
- Optional thread id if not calling from thread that started the test method. May be null.public void startBatch()
startBatch
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
public void endBatch(Properties parameters)
endBatch
in interface org.apache.qpid.junit.extensions.listeners.TKTestListener
parameters
- The optional test parameters to log out with the batch results.public Thread getShutdownHook()
getShutdownHook
in interface org.apache.qpid.junit.extensions.ShutdownHookable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |