Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (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:
  JUnitContext, TimeContext

    public abstract class TestContext

extends LogContext

This class represents a logging context specialized for testing.

A test context is necessary to run a `TestSuite` or `TestCase`. The `default` test context sends results to `System.out` and errors to `System.err`.``

         TestContext.enter(); // Enters default (logs to System.out/System.err)
         try {
             TestContext.run(testSuite);
             TestContext.run(testSuite.tests().get(3)); // Runs specific test case.
             ...
        } finally {
             TestContext.exit(); // Outputs test results statistics.
        }

Users may provide their own test context (or plugin) to output or show test results in various form (e.g. tabular, IDE integraged).``

         TestContext tabularLog = new TestContext() { ... }
         TestContext.enter(tabularLog);
         try {
             TestContext.run(testSuite); // Results sent to spreadsheet.
             ...
         } finally {
             TestContext.exit();
         }

For automatic regression tests, a `regression` context is provided which does not perform any logging but raises an `AssertionException` when an assertion fails.``

         TestContext.enter(TestContext.REGRESSION);
         try {
             TestContext.run(testSuite); // AssertionError if assert fails.
             ...
         } finally {
             TestContext.exit();
         }

Version:
  5.3, March 8, 2009
Author:
  Jean-Marie Dautelle
See Also:
  `TestSuite`, Serialized Form

Field Summary
`static java.lang.Class<? extends LogContext>` | `CONSOLE` Holds a test context logging test results to the system console.
`static Configurable<java.lang.Class<? extends TestContext>>` | `DEFAULT` Holds the test context default implementation (the test report is sent to to `System.out` and test errors are sent to `System.err`).
`static java.lang.Class<? extends 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
`NULL, STANDARD, SYSTEM_OUT`

Fields inherited from class javolution.context.Context
`ROOT`

Constructor Summary
`TestContext()`

Method Summary
`static boolean` | `assertArrayEquals(boolean[] expected, boolean[] actual)` Convenience method equivalent to `assertArrayEquals(expected, actual, null)`.
`static boolean` | `assertArrayEquals(boolean[] expected, boolean[] actual, java.lang.CharSequence message)` Checks the equality of both arrays specified.
`static boolean` | `assertArrayEquals(double[] expected, double[] actual, double delta)` Convenience method equivalent to `assertArrayEquals(expected, actual, delta, null)`.
`static boolean` | `assertArrayEquals(double[] expected, double[] actual, double delta, java.lang.CharSequence message)` Checks the equality of both arrays specified.
`static boolean` | `assertArrayEquals(int[] expected, int[] actual)` Convenience method equivalent to `assertArrayEquals(expected, value, null)`.
`static boolean` | `assertArrayEquals(int[] expected, int[] actual, java.lang.CharSequence message)` Checks the equality of both arrays specified.
`static boolean` | `assertArrayEquals(long[] expected, long[] actual)` Convenience method equivalent to `assertArrayEquals(expected, value, null)`.
`static boolean` | `assertArrayEquals(long[] expected, long[] actual, java.lang.CharSequence message)` Checks the equality of both arrays specified.
`static boolean` | `assertArrayEquals(java.lang.Object[] expected, java.lang.Object[] actual)` Convenience method equivalent to `assertArrayEquals(expected, actual, null)`.
`static boolean` | `assertArrayEquals(java.lang.Object[] expected, java.lang.Object[] actual, java.lang.CharSequence message)` Checks the equality of the arrays specified.
`static boolean` | `assertEquals(double expected, double actual)` Deprecated. Use `assertEquals(expected, actual, delta)` instead
`static boolean` | `assertEquals(double expected, double actual, java.lang.CharSequence message)` Deprecated. Use `assertEquals(expected, actual, delta, message)` instead
`static boolean` | `assertEquals(double expected, double actual, double delta)` Convenience method equivalent to `assertEquals(expected, actual, delta, null)`.
`static boolean` | `assertEquals(double expected, double actual, double delta, java.lang.CharSequence message)` Asserts that two doubles or floats are equal to within a positive delta.
`static boolean` | `assertEquals(int expected, int actual)` Convenience method equivalent to `assertEquals(expected, actual, null)`.
`static boolean` | `assertEquals(int expected, int actual, java.lang.CharSequence message)` Convenience method equivalent to `assertEquals(new Integer(expected), new Integer(actual), message)`.
`static boolean` | `assertEquals(long expected, long actual)` Convenience method equivalent to `assertEquals(expected, actual, null)`.
`static boolean` | `assertEquals(long expected, long actual, java.lang.CharSequence message)` Convenience method equivalent to `assertEquals(new Long(expected), new Long(actual))`.
`static boolean` | `assertEquals(java.lang.Object expected, java.lang.Object actual)` Convenience method equivalent to `assertEquals(expected, actual, null)`.
`static boolean` | `assertEquals(java.lang.Object expected, java.lang.Object actual, java.lang.CharSequence message)` Checks the equality of both objects specified.
`static boolean` | `assertException(java.lang.Class exceptionClass, java.lang.Runnable logic)` Convenience method equivalent to `assertException(exceptionClass, logic, null)`.
`static boolean` | `assertException(java.lang.Class exceptionClass, java.lang.Runnable logic, java.lang.CharSequence message)` Checks that the specified logic raises an instance of the specified exception.
`static boolean` | `assertFalse(boolean actual)` Convenience method equivalent to `assertFalse(actual, null)`.
`static boolean` | `assertFalse(boolean actual, java.lang.CharSequence message)` Convenience method equivalent to `assertEquals(false, actual, message)`.
`static boolean` | `assertNotNull(java.lang.Object actual)` Convenience method equivalent to `assertNotNull(actual, null)`.
`static boolean` | `assertNotNull(java.lang.Object actual, java.lang.CharSequence message)` Convenience method equivalent to `assertTrue(actual !`
`static boolean` | `assertNull(java.lang.Object actual)` Convenience method equivalent to `assertNull(actual, null)`.
`static boolean` | `assertNull(java.lang.Object actual, java.lang.CharSequence message)` Convenience method equivalent to `assertEquals(null, actual, message)`.
`static boolean` | `assertSame(java.lang.Object expected, java.lang.Object actual)` Convenience method equivalent to `assertSame(expected, actual, null)`.
`static boolean` | `assertSame(java.lang.Object expected, java.lang.Object actual, java.lang.CharSequence message)` Checks that both objects specified refer to the same instance.
`static boolean` | `assertTrue(boolean actual)` Convenience method equivalent to `assertTrue(actual, null)`.
`static boolean` | `assertTrue(boolean actual, java.lang.CharSequence message)` Convenience method equivalent to `assertEquals(true, actual, message)`.
`protected boolean` | `doAssert(boolean value, java.lang.CharSequence message)` Asserts the specified value is `true`.
`protected void` | `doRun(TestCase testCase)` Executes the specified test case and logs the results.
`protected void` | `doRun(TestSuite testSuite)` Executes the specified test suite and logs the results.
`static void` | `enter()` Enters the `DEFAULT` test context.
`static void` | `exit()` Exits the current test context.
`static boolean` | `fail()` Convenience method equivalent to `fail(null)`.
`static boolean` | `fail(java.lang.CharSequence message)` Convenience method equivalent to `assertTrue(false, message)`.
`static void` | `run(TestCase testCase)` Executes the specified test case and logs the results to the current test context.
`static void` | `run(TestSuite testSuite)` Executes the specified test suite and logs the results to the current test context.

Methods inherited from class javolution.context.LogContext
`debug, debug, debug, debug, debug, debug, enterAction, error, error, error, error, error, exitAction, getCurrent, getDefault, info, info, info, info, info, info, isDebugLogged, isErrorLogged, isInfoLogged, isLogged, isWarningLogged, logDebug, logError, logInfo, logMessage, logWarning, warning, warning, warning, warning, 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

### DEFAULT

    public static final Configurable<java.lang.Class<? extends TestContext>> DEFAULT

  Holds the test context default implementation (the test report is sent to to `System.out` and test errors are sent to `System.err`).

### CONSOLE

    public static final java.lang.Class<? extends LogContext> CONSOLE

  Holds a test context logging test results to the system console.

### REGRESSION

    public static final java.lang.Class<? extends 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

### enter

    public static void enter()

  Enters the `DEFAULT` test context.

### exit

    public static void exit()

  Exits the current test context.

  Throws:
    `java.lang.ClassCastException` - if the current context is not a test context.

### run

    public static void run(TestSuite testSuite)
                    throws java.lang.Exception

  Executes the specified test suite and logs the results to the current test context.

  Parameters:
    `testSuite` - the test suite to be executed.
  Throws:
    `java.lang.ClassCastException` - if the current logging context is not a test context.
    `java.lang.Exception`

### run

    public static void run(TestCase testCase)
                    throws java.lang.Exception

  Executes the specified test case and logs the results to the current test context.

  Parameters:
    `testCase` - the test case to be executed.
  Throws:
    `java.lang.ClassCastException` - if the current logging context is not a test context.
    `java.lang.Exception`

### assertEquals

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

  Checks the equality of both objects specified.

  Parameters:
    `expected` - the expected result (can be `null`).
    `actual` - the actual result (can be `null`).
    `message` - the message displayed if assert fails or `null` if none.
  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(expected, actual, null)`.

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

### assertSame

    public static boolean assertSame(java.lang.Object expected,
                                     java.lang.Object actual,
                                     java.lang.CharSequence message)

  Checks that both objects specified refer to the same instance.

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

### assertSame

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

  Convenience method equivalent to `assertSame(expected, actual, null)`.

  Parameters:
    `expected` - the expected result (can be `null`).
    `actual` - the actual result (can be `null`).
  Returns:
    `true` if both expected and actual are the same object; `false` otherwise.

### assertTrue

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

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

  Parameters:
    `actual` - the actual value.
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if actual is `true`; `false` otherwise.

### assertTrue

    public static boolean assertTrue(boolean actual)

  Convenience method equivalent to `assertTrue(actual, null)`.

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

### assertFalse

    public static boolean assertFalse(boolean actual,
                                      java.lang.CharSequence message)

  Convenience method equivalent to `assertEquals(false, actual, message)`.

  Parameters:
    `actual` - the actual value.
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if actual is `false`; `false` otherwise.

### assertFalse

    public static boolean assertFalse(boolean actual)

  Convenience method equivalent to `assertFalse(actual, null)`.

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

### assertNull

    public static boolean assertNull(java.lang.Object actual,
                                     java.lang.CharSequence message)

  Convenience method equivalent to `assertEquals(null, actual, message)`.

  Parameters:
    `actual` - the actual value.
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if actual is `null`; `false` otherwise.

### assertNull

    public static boolean assertNull(java.lang.Object actual)

  Convenience method equivalent to `assertNull(actual, null)`.

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

### assertNotNull

    public static boolean assertNotNull(java.lang.Object actual,
                                        java.lang.CharSequence message)

  Convenience method equivalent to `assertTrue(actual != null, message)`.

  Parameters:
    `actual` - the actual value.
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if actual is not `null`; `false` otherwise.

### assertNotNull

    public static boolean assertNotNull(java.lang.Object actual)

  Convenience method equivalent to `assertNotNull(actual, null)`.

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

### assertEquals

    public static boolean assertEquals(int expected,
                                       int actual,
                                       java.lang.CharSequence message)

  Convenience method equivalent to `assertEquals(new Integer(expected), new Integer(actual), message)`.

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

### assertEquals

    public static boolean assertEquals(int expected,
                                       int actual)

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

  Parameters:
    `expected` - the expected result.
    `actual` - the actual result.
  Returns:
    `true` if both expected and actual are equal; `false` otherwise.

### assertEquals

    public static boolean assertEquals(long expected,
                                       long actual,
                                       java.lang.CharSequence message)

  Convenience method equivalent to `assertEquals(new Long(expected), new Long(actual))`.

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

### assertEquals

    public static boolean assertEquals(long expected,
                                       long actual)

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

  Parameters:
    `expected` - the expected result.
    `actual` - the actual result.
  Returns:
    `true` if both expected and actual are equal; `false` otherwise.

### assertEquals

    public static boolean assertEquals(double expected,
                                       double actual,
                                       java.lang.CharSequence message)

  Deprecated. Use `assertEquals(expected, actual, delta, message)` instead

  Convenience method equivalent to `assertEquals(new Double(expected), new Double(actual), message)`.

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

### assertEquals

    public static boolean assertEquals(double expected,
                                       double actual)

  Deprecated. Use `assertEquals(expected, actual, delta)` instead

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

  Parameters:
    `expected` - the expected result.
    `actual` - the actual result.
  Returns:
    `true` if both expected and actual are equal; `false` otherwise.

### assertEquals

    public static boolean assertEquals(double expected,
                                       double actual,
                                       double delta,
                                       java.lang.CharSequence message)

  Asserts that two doubles or floats are equal to within a positive delta. If the expected value is infinity then the delta value is ignored. NaN numbers are considered equal.

  Parameters:
    `expected` - the expected result.
    `actual` - the actual result.
    `delta` - the maximum delta between expected and actual for which both numbers are still considered equal.
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if both expected and actual are approximately equal; `false` otherwise.

### assertEquals

    public static boolean assertEquals(double expected,
                                       double actual,
                                       double delta)

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

  Parameters:
    `expected` - the expected result.
    `actual` - the actual result.
    `delta` - the maximum delta between expected and actual for which both numbers are still considered equal.
  Returns:
    `true` if both expected and actual are approximately equal; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(java.lang.Object[] expected,
                                            java.lang.Object[] actual,
                                            java.lang.CharSequence message)

  Checks the equality of the arrays specified. If expecteds and actuals are `null`, they are considered equal.

  Parameters:
    `expected` - the single dimension array with expected values (can be `null`).
    `actual` - the single dimension array with actual values (can be `null`).
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if both expected and actual have equals elements; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(java.lang.Object[] expected,
                                            java.lang.Object[] actual)

  Convenience method equivalent to `assertArrayEquals(expected, actual, null)`.

  Parameters:
    `expected` - the single dimension array with expected values (can be `null`).
    `actual` - the single dimension array with actual values (can be `null`).

### assertArrayEquals

    public static boolean assertArrayEquals(boolean[] expected,
                                            boolean[] actual,
                                            java.lang.CharSequence message)

  Checks the equality of both arrays specified. If expecteds and actuals are `null`, they are considered equal.

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if both expected and actual have the same values; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(boolean[] expected,
                                            boolean[] actual)

  Convenience method equivalent to `assertArrayEquals(expected, actual, null)`.

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
  Returns:
    `true` if both expected and actual have the same values; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(int[] expected,
                                            int[] actual,
                                            java.lang.CharSequence message)

  Checks the equality of both arrays specified. If expecteds and actuals are `null`, they are considered equal.

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if both expected and actual have the same values; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(int[] expected,
                                            int[] actual)

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

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
  Returns:
    `true` if both expected and actual have the same values; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(long[] expected,
                                            long[] actual,
                                            java.lang.CharSequence message)

  Checks the equality of both arrays specified. If expecteds and actuals are `null`, they are considered equal.

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if both expected and actual have the same values; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(long[] expected,
                                            long[] actual)

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

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
  Returns:
    `true` if both expected and actual have the same values; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(double[] expected,
                                            double[] actual,
                                            double delta,
                                            java.lang.CharSequence message)

  Checks the equality of both arrays specified. If expecteds and actuals are `null`, they are considered equal.

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
    `delta` - the maximum delta between expected and actual for which both numbers are still considered equal.
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if both expected and actual have approximately the same values; `false` otherwise.

### assertArrayEquals

    public static boolean assertArrayEquals(double[] expected,
                                            double[] actual,
                                            double delta)

  Convenience method equivalent to `assertArrayEquals(expected, actual, delta, null)`.

  Parameters:
    `expected` - array (can be `null`).
    `actual` - array (can be `null`).
    `delta` - the maximum delta between expected and actual for which both numbers are still considered equal.
  Returns:
    `true` if both expected and actual have the same values; `false` otherwise.

### assertException

    public static boolean assertException(java.lang.Class exceptionClass,
                                          java.lang.Runnable logic,
                                          java.lang.CharSequence message)

  Checks that the specified logic raises an instance of the specified exception.

  Parameters:
    `exceptionClass` - the type of exception expected.
    `logic` - the logic supposed to produce the desired exception.
    `message` - the message displayed if assert fails or `null` if none.
  Returns:
    `true` if the specified logic raises an exception of specified type; `false` otherwise.

### assertException

    public static boolean assertException(java.lang.Class exceptionClass,
                                          java.lang.Runnable logic)

  Convenience method equivalent to `assertException(exceptionClass, logic, null)`.

### fail

    public static boolean fail(java.lang.CharSequence message)

  Convenience method equivalent to `assertTrue(false, message)`.

### fail

    public static boolean fail()

  Convenience method equivalent to `fail(null)`.

### doRun

    protected void doRun(TestSuite testSuite)
                  throws java.lang.Exception

  Executes the specified test suite and logs the results. The default implementation runs all the test cases.

  Parameters:
    `testSuite` - the test suite to be executed.
  Throws:
    `java.lang.Exception`
  See Also:
    `doRun(javolution.testing.TestCase)`

### doRun

    protected void doRun(TestCase testCase)
                  throws java.lang.Exception

  Executes the specified test case and logs the results. If the test case is not marked `ignored`, the default implementation runs `setUp`, `execute`, `validate` and `tearDown` in sequence.

  Parameters:
    `testCase` - the test case being executed if not marked ignored.
  Throws:
    `java.lang.Exception`

### doAssert

    protected boolean doAssert(boolean value,
                               java.lang.CharSequence message)

  Asserts the specified value is `true`. The default implementation logs an error message including the code location of the assert if the assert checks fails. For example:`

       [error] NaN expected but found Infinity
               at javolution.TextTestSuite$DoubleParseDouble.validate(TextTestSuite.java:389)

  `

  Parameters:
    `value` - the boolean value to be tested.
    `message` - the message to be displayed if assert fails (can be `null`).
  Returns:
    the specified value.

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

Copyright © 2005 - 2009 Javolution.