TestContext (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.test.context

## Class TestContext

- java.lang.Object
- - org.springframework.core.AttributeAccessorSupport
  - - org.springframework.test.context.TestContext

- All Implemented Interfaces:
    Serializable, AttributeAccessor

      public class TestContext
      extends AttributeAccessorSupport

  `TestContext` encapsulates the context in which a test is executed, agnostic of the actual testing framework in use.
  Since:
    2.5
  Author:
    Sam Brannen, Juergen Hoeller
  See Also:
    Serialized Form

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ApplicationContext` | `getApplicationContext()` Get the `application context` for this test context, possibly cached.
    `Class<?>` | `getTestClass()` Get the `test class` for this test context.
    `Throwable` | `getTestException()` Get the `exception` that was thrown during execution of the `test method`.
    `Object` | `getTestInstance()` Get the current `test instance` for this test context.
    `Method` | `getTestMethod()` Get the current `test method` for this test context.
    `void` | `markApplicationContextDirty()` Call this method to signal that the `application context` associated with this test context is dirty and should be reloaded.
    `String` | `toString()` Provide a String representation of this test context's state.

    - ### Methods inherited from class org.springframework.core.AttributeAccessorSupport

      `attributeNames, copyAttributesFrom, equals, getAttribute, hasAttribute, hashCode, removeAttribute, setAttribute`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### getApplicationContext

          public ApplicationContext getApplicationContext()

      Get the `application context` for this test context, possibly cached.
      Returns:
        the application context
      Throws:
        `IllegalStateException` - if an error occurs while retrieving the application context

    - #### getTestClass

          public final Class<?> getTestClass()

      Get the `test class` for this test context.
      Returns:
        the test class (never `null`)

    - #### getTestInstance

          public final Object getTestInstance()

      Get the current `test instance` for this test context.

      Note: this is a mutable property.

      Returns:
        the current test instance (may be `null`)
      See Also:
        `updateState(Object, Method, Throwable)`

    - #### getTestMethod

          public final Method getTestMethod()

      Get the current `test method` for this test context.

      Note: this is a mutable property.

      Returns:
        the current test method (may be `null`)
      See Also:
        `updateState(Object, Method, Throwable)`

    - #### getTestException

          public final Throwable getTestException()

      Get the `exception` that was thrown during execution of the `test method`.

      Note: this is a mutable property.

      Returns:
        the exception that was thrown, or `null` if no exception was thrown
      See Also:
        `updateState(Object, Method, Throwable)`

    - #### markApplicationContextDirty

          public void markApplicationContextDirty()

      Call this method to signal that the `application context` associated with this test context is dirty and should be reloaded. Do this if a test has modified the context (for example, by replacing a bean definition).

    - #### toString

          public String toString()

      Provide a String representation of this test context's state.
      Overrides:
        `toString` in class `Object`