From bc6927e60190f33003a0bf4c18686aaad3ecc311 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 29 Sep 2011 13:28:37 +0000 Subject: [PATCH] [SPR-8240] Documented ContextLoaders in the testing chapter. --- spring-framework-reference/src/testing.xml | 99 +++++++++++++++++++--- 1 file changed, 85 insertions(+), 14 deletions(-) diff --git a/spring-framework-reference/src/testing.xml b/spring-framework-reference/src/testing.xml index 901e948b44..6ffcf9438e 100644 --- a/spring-framework-reference/src/testing.xml +++ b/spring-framework-reference/src/testing.xml @@ -684,9 +684,10 @@ public void testProcessWithoutTransaction() {
Standard Annotation Support - The following non-test-specific annotations are supported with - standard semantics for all configurations of the Spring TestContext - Framework. + The following annotations are supported with standard semantics + for all configurations of the Spring TestContext Framework. Note that + these annotations are not specific to tests and can be used anywhere + in the Spring Framework. @@ -888,11 +889,12 @@ public void testProcessRepeatedly() { The following section provides an overview of the internals of the TestContext framework. If you are only interested in using the framework and not necessarily interested in extending it with your own custom - listeners, feel free to go directly to the configuration (context management, dependency injection, transaction management), support classes, and context + management, dependency + injection, transaction + management), support + classes, and annotation support sections. @@ -902,25 +904,36 @@ public void testProcessRepeatedly() { The core of the framework consists of the TestContext and TestContextManager classes and the - TestExecutionListener interface. A + TestExecutionListener, + ContextLoader, and + SmartContextLoader interfaces. A TestContextManager is created on a per-test - basis. The TestContextManager in turn manages a + basis (e.g., for the execution of a single test method in JUnit). The + TestContextManager in turn manages a TestContext that holds the context of the current test. The TestContextManager also updates the state of the TestContext as the test progresses and delegates to TestExecutionListeners, which instrument the actual test execution, by providing dependency - injection, managing transactions, and so on. Consult the Javadoc and - the Spring test suite for further information and examples of various - configurations. + injection, managing transactions, and so on. A + ContextLoader (or + SmartContextLoader) is responsible for + loading an ApplicationContext for a + given test class. Consult the Javadoc and the Spring test suite for + further information and examples of various implementations. TestContext: Encapsulates the context in which a test is executed, agnostic of the actual testing framework in use, and provides context management and caching - support for the test instance for which it is responsible. + support for the test instance for which it is responsible. The + TestContext also delegates to a + ContextLoader (or + SmartContextLoader) to load an + ApplicationContext if + requested. @@ -977,6 +990,64 @@ public void testProcessRepeatedly() { transactional test execution with default rollback semantics. + + + ContextLoader: Strategy + interface for loading an + ApplicationContext for an + integration test managed by the Spring TestContext + Framework. + + As of Spring 3.1, implement + SmartContextLoader instead of this + interface in order to provide support for configuration classes + and active bean definition profiles. + + + + SmartContextLoader: Extension + of the ContextLoader interface + introduced in Spring 3.1. + + The SmartContextLoader SPI + supersedes the ContextLoader SPI + that was introduced in Spring 2.5. Specifically, a + SmartContextLoader can choose to + process either resource locations or + configuration classes. Furthermore, a + SmartContextLoader can set active + bean definition profiles in the context that it loads. + + Spring provides the following out-of-the-box + implementations: + + + + DelegatingSmartContextLoader: the + default loader which delegates internally to an + AnnotationConfigContextLoader or a + GenericXmlContextLoader depending on + the configuration declared for the test class. + + + + AnnotationConfigContextLoader: + loads an application context from + @Configuration classes. + + + + GenericXmlContextLoader: loads + and application context from XML resource locations. + + + + GenericPropertiesContextLoader: + loads an application context from Java Properties + files. + + + The following three sections explain how to configure the