Interface TestContext

    • Method Detail

      • getApplicationContext

        ApplicationContext getApplicationContext()
        Get the application context for this test context, possibly cached.

        Implementations of this method are responsible for loading the application context if the corresponding context has not already been loaded, potentially caching the context as well.

        Returns:
        the application context (never null)
        Throws:
        IllegalStateException - if an error occurs while retrieving the application context
      • markApplicationContextDirty

        void markApplicationContextDirty​(DirtiesContext.HierarchyMode hierarchyMode)
        Call this method to signal that the application context associated with this test context is dirty and should be removed from the context cache.

        Do this if a test has modified the context — for example, by modifying the state of a singleton bean, modifying the state of an embedded database, etc.

        Parameters:
        hierarchyMode - the context cache clearing mode to be applied if the context is part of a hierarchy (may be null)
      • updateState

        void updateState​(Object testInstance,
                         Method testMethod,
                         Throwable testException)
        Update this test context to reflect the state of the currently executing test.

        Caution: concurrent invocations of this method might not be thread-safe, depending on the underlying implementation.

        Parameters:
        testInstance - the current test instance (may be null)
        testMethod - the current test method (may be null)
        testException - the exception that was thrown in the test method, or null if no exception was thrown