Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.testing
Class TestContext

    java.lang.Object
      javolution.context.Context
          javolution.context.LogContext
              javolution.testing.TestContext

All Implemented Interfaces:
  java.io.Serializable, XMLSerializable

Direct Known Subclasses:
  TimeContext

    public abstract class TestContext

extends LogContext

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();
         }

Version:
  5.2, August 5, 2007
Author:
  Jean-Marie Dautelle
See Also:
  `TestCase`, Serialized Form

Field 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

### REGRESSION

    public static final java.lang.Class<TestContext> REGRESSION

  Holds an implementation which does not perform any logging but raises an `AssertionException` when an assertion fails. This implementation can be used for automatic regression tests.

Constructor Detail

### TestContext

    public TestContext()

Method Detail

### test

    public static void test(TestCase testCase)

  Runs an individual test case (possibly multiple times) and logs the results. If the current logging context is a test context then `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.

  Parameters:
    `testCase` - the test case being executed.

### assertEquals

    public static boolean assertEquals(java.lang.String message,
                                       java.lang.Object expected,
                                       java.lang.Object actual)

  Checks the equality of both objects specified. If the current logging context is a test context then `doAssertEquals(String, Object, Object)` is called; otherwise an error message is logged only if the assert fails.

  Parameters:
    `message` - the message displayed if assert fails (can be `null`)
    `expected` - the expected result (can be `null`).
    `actual` - the actual result (can be `null`).
  Returns:
    `true` if both expected and actual are equal; `false` otherwise.

### assertEquals

    public static boolean assertEquals(java.lang.Object expected,
                                       java.lang.Object actual)

  Convenience method equivalent to `assertEquals(null, expected, value)`.

  Parameters:
    `expected` - the expected result (can be `null`).
    `actual` - the actual result (can be `null`).

### assertTrue

    public static boolean assertTrue(java.lang.String message,
                                     boolean actual)

  Convenience method equivalent to `assertEquals(message, true, value)`.

  Parameters:
    `message` - the message displayed if assert fails (can be `null`)
    `actual` - the actual value.
  Returns:
    `true` if actual is `true`; `false` otherwise.

### assertTrue

    public static boolean assertTrue(boolean actual)

  Convenience method equivalent to `assertEquals(null, true, value)`.

  Parameters:
    `actual` - the actual value.
  Returns:
    `true` if actual is `true`; `false` otherwise.

### doTest

    public abstract void doTest(TestCase testCase)

  Executes the specified test case and logs the results.

  Parameters:
    `testCase` - the test case being executed.

### doAssertEquals

    public abstract boolean doAssertEquals(java.lang.String message,
                                           java.lang.Object expected,
                                           java.lang.Object actual)

  Asserts that two objects are equal.

  Parameters:
    `message` - the message displayed if assert fails (can be `null`)
    `expected` - the expected result (can be `null`).
    `actual` - the actual result (can be `null`).
  Returns:
    `true` if both expected and actual are equal; `false` otherwise.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2007 Javolution.