com.thesett.junit.extensions.TKTestResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-toolkit Show documentation
Show all versions of junit-toolkit Show documentation
JUnit Toolkit enhances JUnit with performance testing, asymptotic behaviour analysis, and concurrency testing.
/*
* Copyright The Sett Ltd, 2005 to 2014.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.thesett.junit.extensions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import com.thesett.junit.extensions.listeners.TKTestListener;
/**
* 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
* {@link TKTestListener}s 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.
*
*
* @author Rupert Smith
* @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.
* @todo 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 {@link AsymptoticTestDecorator}.
* The {@link AsymptoticTestDecorator#run} method takes a TestResult as an argument and cannot easily get to the
* {@link 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.
* @todo 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.
* @todo Get rid of the delay logic. Will be replaced by throttle control.
*/
public class TKTestResult extends TestResult
{
/** Used for logging. */
/*private static final Logger log = Logger.getLogger(TKTestResult.class);*/
/** The delay between two tests. */
private int delay;
/**
* This flag indicates that the #completeTest method of the timing controller has been called. Once this has been
* called once, the end test event for the whole test method should be ignored because tests have taken charge of
* outputing their own timings.
*/
private boolean completeTestUsed;
/**
* Thread locals to hold test start time for non-instrumented tests. (Instrumented tests hold their own measurement
* data).
*/
// private Hashtable threadStartTimeMap = new Hashtable();
private final ThreadLocal© 2015 - 2024 Weber Informatics LLC | Privacy Policy