org.apache.qpid.junit.extensions.listeners
Class ConsoleTestListener

java.lang.Object
  extended by org.apache.qpid.junit.extensions.listeners.ConsoleTestListener
All Implemented Interfaces:
junit.framework.TestListener, TKTestListener

public class ConsoleTestListener
extends Object
implements junit.framework.TestListener, TKTestListener

ConsoleTestListener provides feedback to the console, as test timings are taken, by drawing a '.', or an 'E', or an 'F', for each test that passes, is in error or fails. It does this for every test result registered with the framework, not just on the completion of each test method as the JUnit one does. It also uses a throttle to cap the rate of dot drawing, as exessively high rates can degrade test performance without providing much usefull feedback to the user. Unlike the JUnit dot drawing feedback, this one will correctly wrap lines when tests are run concurrently (the rate capping ensures that this does not become a hot-spot for thread contention).

Where rate capping causes the conflation of multiple requested dots into a single dot, the dot that is actually drawn will be the worst result within the conflation period, that is, error is worse than fail which is worse than pass.

CRC Card
Responsibilities Collaborations
Draw dots as each test result completes, at a capped rate.


Field Summary
(package private)  Throttle throttle
          Used to throttle the dot writing rate.
 
Constructor Summary
ConsoleTestListener()
          Creates a dot drawing feedback test listener, set by default to 80 columns at 80 dots per second capped rate.
 
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)
          A test ended.
 void endTest(junit.framework.Test test, Long threadId)
          Called when a test completes.
 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)
          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

throttle

Throttle throttle
Used to throttle the dot writing rate.

Constructor Detail

ConsoleTestListener

public ConsoleTestListener()
Creates a dot drawing feedback test listener, set by default to 80 columns at 80 dots per second capped rate.

Method Detail

addError

public void addError(junit.framework.Test test,
                     Throwable t)
An error occurred.

Specified by:
addError in interface junit.framework.TestListener
Parameters:
test - The test in error. Ignored.
t - The error that the test threw. Ignored.

addFailure

public void addFailure(junit.framework.Test test,
                       junit.framework.AssertionFailedError t)
A failure occurred.

Specified by:
addFailure in interface junit.framework.TestListener
Parameters:
test - The test that failed. Ignored.
t - The assertion failure that the test threw. Ignored.

endTest

public void endTest(junit.framework.Test test)
A test ended.

Specified by:
endTest in interface junit.framework.TestListener
Parameters:
test - The test that ended. Ignored.

startTest

public void startTest(junit.framework.Test test)
A test started.

Specified by:
startTest in interface junit.framework.TestListener
Parameters:
test - The test that started. Ignored.

reset

public 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.

Specified by:
reset in interface TKTestListener
Parameters:
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.

timing

public 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.

Specified by:
timing in interface TKTestListener
Parameters:
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.

timing2

public void timing2(junit.framework.Test test,
                    Long nanos,
                    Long threadId)
Optionally called every time a test completes with the second timing test.

Specified by:
timing2 in interface TKTestListener
Parameters:
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.

memoryUsed

public 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.

Specified by:
memoryUsed in interface TKTestListener
Parameters:
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.

parameterValue

public 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.

Specified by:
parameterValue in interface TKTestListener
Parameters:
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.

concurrencyLevel

public 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.

Specified by:
concurrencyLevel in interface TKTestListener
Parameters:
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.

endTest

public void endTest(junit.framework.Test test,
                    Long threadId)
Called when a test completes. Success, failure and errors. This method should be used when registering an end test from a different thread than the one that started the test.

Specified by:
endTest in interface TKTestListener
Parameters:
test - The test which completed.
threadId - Optional thread id if not calling from thread that started the test method. May be null.

addFailure

public void addFailure(junit.framework.Test test,
                       junit.framework.AssertionFailedError e,
                       Long threadId)
Called when a test completes to mark it as a test fail. This method should be used when registering a failure from a different thread than the one that started the test.

Specified by:
addFailure in interface TKTestListener
Parameters:
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.

startBatch

public void startBatch()
Notifies listeners of the start of a complete run of tests.

Specified by:
startBatch in interface TKTestListener

endBatch

public void endBatch(Properties parameters)
Notifies listeners of the end of a complete run of tests.

Specified by:
endBatch in interface TKTestListener
Parameters:
parameters - The optional test parameters to log out with the batch results.

properties

public void properties(Properties properties)
Notifies listeners of the tests read/set properties.

Specified by:
properties in interface TKTestListener
Parameters:
properties - The tests read/set properties.


Licensed to the Apache Software Foundation