org.apache.qpid.junit.extensions
Class TKTestResult

java.lang.Object
  extended by junit.framework.TestResult
      extended by org.apache.qpid.junit.extensions.TKTestResult

public class TKTestResult
extends junit.framework.TestResult

TKTestResult extends TestResult in order to calculate test timings, to pass the variable integer parameter for parameterized test cases to those test cases and to introduce an optional delay before test starts. Interested TKTestListeners may be attached to this and will be informed of all relevant test statistics.

CRC Card
Responsibilities Collaborations
Calculate test timings.
Inform timing listeners of timings.
Inform memory listeners of memory readings.
Inform parameters listeners of parameters.
Pass the integer parameter to parameterized test cases.
Provide verbose test information on test start and end.

Todo:
Move the verbose test information on test start/end into a test listener instead. It confuses the intention of this class. Could also move the delay into a listener but that seems less appropriate as it would be a side-effecting listener. Delay and timing calculation are fundamental enough to this class., The need for this class to act as a place-holder for the integer parameter for parameterized test cases is because this behaviour has been factored out into a test decorator class, see AsymptoticTestDecorator. The AsymptoticTestDecorator.run(junit.framework.TestResult) method takes a TestResult as an argument and cannot easily get to the AsymptoticTestCase class other than through this class. The option of using this class as a place hold for this value was chosen. Alternatively this class could provide a method for decorators to access the underlying test case through and then leave the setting of this parameter to the decorator which is a more natural home for this behaviour. It would also provide a more general framework for decorators., The memory usage may need to be moved in closer to the test method invocation so that as little code as possible exists between it and the test or the results may be obscured. In fact it certainly does as the teardown method is getting called first. Wouldn't be a bad idea to move the timing code in closer too., Get rid of the delay logic. Will be replaced by throttle control.

Field Summary
 
Fields inherited from class junit.framework.TestResult
fErrors, fFailures, fListeners, fRunTests
 
Constructor Summary
TKTestResult(int delay, String testCaseName)
          Creates a new TKTestResult object.
 
Method Summary
 void addTKTestListener(TKTestListener listener)
          Adds a timing listener to pass all timing events to.
 void endTest(junit.framework.Test test)
          Callback method use to inform this result that a test was completed.
 int getN()
          Gets the integer parameter to pass to parameterized test cases.
protected  String getTestInfo(junit.framework.Test test)
          Helper method that generats a String of verbose information about a test.
 void notifyEndBatch()
          Called by the test runner to notify this that the current test batch has been ended.
 void notifyStartBatch()
          Called by the test runner to notify this that a new test batch is being begun.
 void notifyTestProperties(Properties properties)
          Called by the test runner to notify this of the properties that the test is using.
protected  void run(junit.framework.TestCase test)
          Intercepts the execution of a test case to pass the variable integer parameter to a test if it is a parameterized test case.
 void setConcurrencyLevel(int concurrencyLevel)
          Sets the concurrency level to pass into the test result.
 void setN(int n)
          Sets the integer parameter to pass to parameterized test cases.
 void shutdownNow()
          Tells this test result that it should stop running tests.
 void startTest(junit.framework.Test test)
          Callback method use to inform this test result that a test will be started.
 String toString()
          Prints a string summary of this class, mainly for debugging purposes.
 
Methods inherited from class junit.framework.TestResult
addError, addFailure, addListener, errorCount, errors, failureCount, failures, removeListener, runCount, runProtected, shouldStop, stop, wasSuccessful
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TKTestResult

public TKTestResult(int delay,
                    String testCaseName)
Creates a new TKTestResult object.

Parameters:
delay - A delay in milliseconds to introduce before every test start.
testCaseName - The name of the test case that this is the TestResult object for.
Method Detail

startTest

public void startTest(junit.framework.Test test)
Callback method use to inform this test result that a test will be started. Waits for the configured delay time if one has been set, starts the timer, then delegates to the super class implementation.

Overrides:
startTest in class junit.framework.TestResult
Parameters:
test - The test to be started.

endTest

public void endTest(junit.framework.Test test)
Callback method use to inform this result that a test was completed. This calculates how long the test took to run, then delegates to the super class implementation.

Overrides:
endTest in class junit.framework.TestResult
Parameters:
test - The test that has ended.

getN

public int getN()
Gets the integer parameter to pass to parameterized test cases.

Returns:
The value of the integer parameter.

setN

public void setN(int n)
Sets the integer parameter to pass to parameterized test cases.

Parameters:
n - The new value of the integer parameter.

addTKTestListener

public void addTKTestListener(TKTestListener listener)
Adds a timing listener to pass all timing events to.

Parameters:
listener - The timing listener to register.

notifyStartBatch

public void notifyStartBatch()
Called by the test runner to notify this that a new test batch is being begun. This method forwards this notification to all batch listeners.


notifyEndBatch

public void notifyEndBatch()
Called by the test runner to notify this that the current test batch has been ended. This method forwards this notification to all batch listener.


notifyTestProperties

public void notifyTestProperties(Properties properties)
Called by the test runner to notify this of the properties that the test is using.

Parameters:
properties - The tests set/read properties.

run

protected void run(junit.framework.TestCase test)
Intercepts the execution of a test case to pass the variable integer parameter to a test if it is a parameterized test case.

Overrides:
run in class junit.framework.TestResult
Parameters:
test - The test to run.

getTestInfo

protected String getTestInfo(junit.framework.Test test)
Helper method that generats a String of verbose information about a test. This includes the thread name, test class name and test method name.

Parameters:
test - The test to generate the info string for.
Returns:
Returns a string with the thread name, test class name and test method name.

setConcurrencyLevel

public void setConcurrencyLevel(int concurrencyLevel)
Sets the concurrency level to pass into the test result.

Parameters:
concurrencyLevel - The concurrency level the tests are running out.

shutdownNow

public void shutdownNow()
Tells this test result that it should stop running tests. Once this method has been called this test result will not start any new tests, and any tests that use the timing controller will be passed interrupted exceptions, to indicate that they should end immediately. Usually the caller of this method will introduce a short wait to allow an opporunity for running tests to complete, before forcing the shutdown of the JVM.


toString

public String toString()
Prints a string summary of this class, mainly for debugging purposes.

Overrides:
toString in class Object
Returns:
A string summary of this class, mainly for debugging purposes.


Licensed to the Apache Software Foundation