public abstract class TimeContext extends TestContext
This class represents a test context
specialized
for measuring execution time.
TimeContext
implementations may perform assertions based upon the
execution time. For example:
class MyTestCase extends TestCase() {
...
protected void validate() {
long ns = TimeContext.getAverageTime("ns");
TestContext.assertTrue(ns < 100); // Error if execution time is more than 100 ns.
...
}
}
Modifier and Type | Field and Description |
---|---|
static Configurable<java.lang.Class<? extends TimeContext>> |
DEFAULT
Holds the time context default implementation (by default logs
average and minimum execution time to
System.out ). |
static java.lang.Class<? extends TimeContext> |
REGRESSION
Holds an implementation which does not perform any logging but raises an
AssertionException when an assertion fails, including any timing
assertion. |
static Configurable<java.lang.Integer> |
TEST_DURATION_MS
Holds the minimum duration of each test execution (default 1000 ms).
|
CONSOLE
NULL, STANDARD, SYSTEM_OUT
Constructor and Description |
---|
TimeContext() |
Modifier and Type | Method and Description |
---|---|
protected void |
doRun(TestCase testCase)
Benchmarks the specified test case and logs the results.
|
static void |
enter()
Enters the
DEFAULT time context. |
static void |
exit()
Exits the current time context.
|
static long |
getAverageTime(java.lang.String unit)
Returns the average execution time of the latest execution performed or
-1 if the current context is not a time context. |
long |
getAverageTimeInPicoSeconds()
Returns the average execution time of the latest execution stated in
pico-seconds.
|
static long |
getMaximumTime(java.lang.String unit)
Returns the maximum execution time of the latest execution performed or
-1 if the current context is not a time context. |
long |
getMaximumTimeInPicoSeconds()
Returns the maximmum execution time of the latest execution stated in
pico-seconds.
|
static long |
getMinimumTime(java.lang.String unit)
Returns the minimum execution time of the latest execution performed or
-1 if the current context is not a time context. |
long |
getMinimumTimeInPicoSeconds()
Returns the minimum execution time of the latest execution stated in
pico-seconds.
|
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertException, assertException, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, doAssert, doRun, fail, fail, run, run
debug, debug, debug, enterAction, error, error, error, error, error, error, error, exitAction, getCurrentLogContext, getDefault, info, info, info, isDebugLogged, isErrorLogged, isInfoLogged, isLogged, isWarningLogged, logDebug, logError, logInfo, logMessage, logWarning, warning, warning, warning
enter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toString
public static final java.lang.Class<? extends TimeContext> REGRESSION
AssertionException
when an assertion fails, including any timing
assertion.public static final Configurable<java.lang.Integer> TEST_DURATION_MS
public static final Configurable<java.lang.Class<? extends TimeContext>> DEFAULT
System.out
).public static void enter()
DEFAULT
time context.public static void exit()
java.lang.ClassCastException
- if the context is not a time context.public static long getMinimumTime(java.lang.String unit)
-1
if the current context is not a time context.unit
- one of "s", "ms", "us", "ns", "ps"
public static long getAverageTime(java.lang.String unit)
-1
if the current context is not a time context.unit
- one of "s", "ms", "us", "ns", "ps"
public static long getMaximumTime(java.lang.String unit)
-1
if the current context is not a time context.unit
- one of "s", "ms", "us", "ns", "ps"
public long getMinimumTimeInPicoSeconds()
public long getAverageTimeInPicoSeconds()
public long getMaximumTimeInPicoSeconds()
protected void doRun(TestCase testCase) throws java.lang.Exception
doRun
in class TestContext
testCase
- the test case being executed if not marked ignored.java.lang.Exception
Copyright © 2005 - 2007 Javolution.