public class

TestContext

extends AttributeAccessorSupport
java.lang.Object
   ↳ org.springframework.core.AttributeAccessorSupport
     ↳ org.springframework.test.context.TestContext

Class Overview

TestContext encapsulates the context in which a test is executed, agnostic of the actual testing framework in use.

Summary

Public Methods
ApplicationContext getApplicationContext()
Get the application context for this test context, possibly cached.
final Class<?> getTestClass()
Get the test class for this test context.
final Throwable getTestException()
Get the exception that was thrown during execution of the test method.
final Object getTestInstance()
Get the current test instance for this test context.
final 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.
[Expand]
Inherited Methods
From class org.springframework.core.AttributeAccessorSupport
From class java.lang.Object
From interface org.springframework.core.AttributeAccessor

Public Methods

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

public final Class<?> getTestClass ()

Get the test class for this test context.

Returns
  • the test class (never null)

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)

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)

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)

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).

public String toString ()

Provide a String representation of this test context's state.