|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavolution.context.Context
javolution.context.LogContext
javolution.testing.TestContext
public abstract class TestContext
This class represents a logging context specialized for testing.
Custom implementations may output results in varied form (e.g. tabular)
and/or perform all kind of measurements (e.g. timing
,
memory usage, etc.) For example:
TestContext tabularLog = new TestContext() { ... } // Outputs to spreadsheet.
TestContext.enter(tabularLog);
try {
TestContext.run(new myTestSuite());
...
} finally {
TestContext.exit();
}
For automatic regression tests, developers may use the
REGRESSION
implementation which does not perform any
logging but raises an AssertionException
when an assertion fails.
For example:
TestContext.enter(TestContext.REGRESSION);
try {
TestContext.run(new myTestSuite()); // AssertionError is one assertion fails.
...
} finally {
TestContext.exit();
}
TestCase
,
Serialized FormField Summary | |
---|---|
static java.lang.Class<TestContext> |
REGRESSION
Holds an implementation which does not perform any logging but raises an AssertionException when an assertion fails. |
Fields inherited from class javolution.context.LogContext |
---|
CONSOLE, DEFAULT, NULL, STANDARD, SYSTEM_OUT |
Fields inherited from class javolution.context.Context |
---|
ROOT |
Constructor Summary | |
---|---|
TestContext()
|
Method Summary | |
---|---|
static boolean |
assertEquals(java.lang.Object expected,
java.lang.Object actual)
Convenience method equivalent to assertEquals(null, expected, value) . |
static boolean |
assertEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
Checks the equality of both objects specified. |
static boolean |
assertTrue(boolean actual)
Convenience method equivalent to assertEquals(null, true, value) . |
static boolean |
assertTrue(java.lang.String message,
boolean actual)
Convenience method equivalent to assertEquals(message, true, value) . |
abstract boolean |
doAssertEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects are equal. |
abstract void |
doTest(TestCase testCase)
Executes the specified test case and logs the results. |
static void |
test(TestCase testCase)
Runs an individual test case (possibly multiple times) and logs the results. |
Methods inherited from class javolution.context.LogContext |
---|
enterAction, error, error, error, error, error, exitAction, getCurrent, getDefault, info, info, isErrorLogged, isInfoLogged, isWarningLogged, logError, logError, logInfo, logInfo, logWarning, logWarning, warning, warning |
Methods inherited from class javolution.context.Context |
---|
enter, enter, exit, exit, getOuter, getOwner, setCurrent, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Class<TestContext> REGRESSION
AssertionException
when an assertion fails.
This implementation can be used for automatic regression tests.
Constructor Detail |
---|
public TestContext()
Method Detail |
---|
public static void test(TestCase testCase)
doTest(TestCase)
is called; otherwise the name of
test case is logged (info), the test case is excuted once
and the test results are written to the current logging context.
testCase
- the test case being executed.public static boolean assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
doAssertEquals(String, Object, Object)
is called;
otherwise an error message is logged only if the assert fails.
message
- the message displayed if assert fails (can be null
)expected
- the expected result (can be null
).actual
- the actual result (can be null
).
true
if both expected and actual are equal;
false
otherwise.public static boolean assertEquals(java.lang.Object expected, java.lang.Object actual)
assertEquals(null, expected, value)
.
expected
- the expected result (can be null
).actual
- the actual result (can be null
).public static boolean assertTrue(java.lang.String message, boolean actual)
assertEquals(message, true, value)
.
message
- the message displayed if assert fails (can be null
)actual
- the actual value.
true
if actual is true
;
false
otherwise.public static boolean assertTrue(boolean actual)
assertEquals(null, true, value)
.
actual
- the actual value.
true
if actual is true
;
false
otherwise.public abstract void doTest(TestCase testCase)
testCase
- the test case being executed.public abstract boolean doAssertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
message
- the message displayed if assert fails (can be null
)expected
- the expected result (can be null
).actual
- the actual result (can be null
).
true
if both expected and actual are equal;
false
otherwise.
|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |