Spring Framework

org.springframework.test.context
Class TestContext

java.lang.Object
  extended by org.springframework.core.AttributeAccessorSupport
      extended by org.springframework.test.context.TestContext
All Implemented Interfaces:
java.io.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
 ApplicationContext getApplicationContext()
          Get the application context for this test context, possibly cached.
 java.lang.Class<?> getTestClass()
          Get the test class for this test context.
 java.lang.Throwable getTestException()
          Get the exception that was thrown during execution of the test method.
 java.lang.Object getTestInstance()
          Get the current test instance for this test context.
 java.lang.reflect.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.
 java.lang.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:
java.lang.IllegalStateException - if an error occurs while retrieving the application context

getTestClass

public final java.lang.Class<?> getTestClass()
Get the test class for this test context.

Returns:
the test class (never null)

getTestInstance

public final java.lang.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 java.lang.reflect.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 java.lang.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 java.lang.String toString()
Provide a String representation of this test context's state.

Overrides:
toString in class java.lang.Object

Spring Framework