@@ -925,8 +925,8 @@ Framework 4.0 introduces several new features for use in unit and integration te
925
925
926
926
* Almost all annotations in the `spring-test` module (e.g., `@ContextConfiguration`,
927
927
`@WebAppConfiguration`, `@ContextHierarchy`, `@ActiveProfiles`, etc.) can now be used
928
- as <<beans-meta -annotations,meta-annotations>> to create custom _composed annotations_
929
- and reduce configuration duplication across tests.
928
+ as <<integration-testing -annotations-meta ,meta-annotations>> to create custom
929
+ _composed annotations_ and reduce configuration duplication across tests.
930
930
* Active bean definition profiles can now be resolved programmatically, simply by
931
931
implementing a custom <<testcontext-ctx-management-env-profiles-ActiveProfilesResolver,`ActiveProfilesResolver`>>
932
932
and registering it via the `resolver` attribute of `@ActiveProfiles`.
@@ -18372,6 +18372,80 @@ well as any __set up__ or __tear down__ of the test fixture.
18372
18372
----
18373
18373
18374
18374
18375
+ [[integration-testing-annotations-meta]]
18376
+ ===== Meta-Annotation Support for Testing
18377
+ As of Spring Framework 4.0, it is now possible to use test-related annotations
18378
+ as <<beans-meta-annotations,meta-annotations>> in order to create custom
18379
+ _composed annotations_ and reduce configuration duplication across tests.
18380
+
18381
+ Each of the following may be used as meta-annotations in conjunction with the
18382
+ <<testcontext-framework,TestContext framework>>.
18383
+
18384
+ * `@ContextConfiguration`
18385
+ * `@ContextHierarchy`
18386
+ * `@ActiveProfiles`
18387
+ * `@DirtiesContext`
18388
+ * `@WebAppConfiguration`
18389
+ * `@TestExecutionListeners`
18390
+ * `@Transactional`
18391
+ * `@BeforeTransaction`
18392
+ * `@AfterTransaction`
18393
+ * `@TransactionConfiguration`
18394
+ * `@Rollback`
18395
+ * `@Repeat`
18396
+ * `@Timed`
18397
+ * `@IfProfileValue`
18398
+ * `@ProfileValueSourceConfiguration`
18399
+
18400
+ For example, if we discover that we are repeating the following configuration
18401
+ across our JUnit-based test suite...
18402
+
18403
+ [source,java,indent=0]
18404
+ [subs="verbatim,quotes"]
18405
+ ----
18406
+ @RunWith(SpringJUnit4ClassRunner.class)
18407
+ @ContextConfiguration({"/app-config.xml", "/test-data-access-config.xml"})
18408
+ @ActiveProfiles("dev")
18409
+ @Transactional
18410
+ public class OrderRepositoryTests { }
18411
+
18412
+ @RunWith(SpringJUnit4ClassRunner.class)
18413
+ @ContextConfiguration({"/app-config.xml", "/test-data-access-config.xml"})
18414
+ @ActiveProfiles("dev")
18415
+ @Transactional
18416
+ public class UserRepositoryTests { }
18417
+ ----
18418
+
18419
+ We can reduce the above duplication by introducing a custom _composed annotation_
18420
+ that centralizes the common test configuration like this:
18421
+
18422
+ [source,java,indent=0]
18423
+ [subs="verbatim,quotes"]
18424
+ ----
18425
+ @Target(ElementType.TYPE)
18426
+ @Retention(RetentionPolicy.RUNTIME)
18427
+ @ContextConfiguration({"/app-config.xml", "/test-data-access-config.xml"})
18428
+ @ActiveProfiles("dev")
18429
+ @Transactional
18430
+ public @interface TransactionalDevTest { }
18431
+ ----
18432
+
18433
+ Then we can use our custom `@TransactionalDevTest` annotation to simplify the
18434
+ configuration of individual test classes as follows:
18435
+
18436
+ [source,java,indent=0]
18437
+ [subs="verbatim,quotes"]
18438
+ ----
18439
+ @RunWith(SpringJUnit4ClassRunner.class)
18440
+ @TransactionalDevTest
18441
+ public class OrderRepositoryTests { }
18442
+
18443
+ @RunWith(SpringJUnit4ClassRunner.class)
18444
+ @TransactionalDevTest
18445
+ public class UserRepositoryTests { }
18446
+ ----
18447
+
18448
+
18375
18449
18376
18450
[[testcontext-framework]]
18377
18451
==== Spring TestContext Framework
0 commit comments