Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7827

Provide meta-annotation support for test-related annotations

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.0.5
    • Fix Version/s: 4.0 RC1
    • Component/s: Test
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Overview

      Spring 3.0 already allows component stereotypes to be used in a meta-annotation fashion, for example by creating a custom @TransactionalService stereotype annotation which combines @Transactional and @Service in a single, reusable, application-specific annotation.

      As mentioned in various forums, a JIRA comment, and discussions I've had with Spring users, it would be beneficial to provide similar meta-annotation support for test-related annotations.

      Given a custom @TransactionalTest stereotype annotation (see code listing below), multiple test classes in the application's test suite could rely on centralized configuration of the context and transaction configuration and thus avoid unnecessary duplication. See UserRepositoryIntegrationTests for an example.

      Notes on JUnit

      Naturally, Spring cannot provide meta-annotation support for JUnit's @RunWith annotation, since @RunWith is processed by JUnit internals. Developers would therefore still be required to specify SpringJUnit4ClassRunner as the runner for each individual test class.


      Deliverables

      Provide meta-annotation support for the following annotations within the context of the TestContext framework.

      1. @ContextConfiguration
      2. @WebAppConfiguration
      3. @ContextHierarchy
      4. @ActiveProfiles
      5. @DirtiesContext
      6. @TestExecutionListeners
      7. @IfProfileValue
      8. @ProfileValueSourceConfiguration
      9. @Transactional
      10. @BeforeTransaction
      11. @AfterTransaction
      12. @TransactionConfiguration
      13. @Rollback
      14. @Repeat
      15. @Timed

      Code Examples

      @TransactionalTest stereotype
      @Transactional
      @ContextConfiguration({"/app-config.xml", "/test-data-access-config.xml"})
      public @interface TransactionalTest {}
      
      UserRepositoryIntegrationTests
      @TransactionalTest
      @RunWith(SpringJUnit4ClassRunner.class)
      public class UserRepositoryIntegrationTests { /* ... */ }
      

      Further Resources


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sbrannen Sam Brannen
                Reporter:
                sbrannen Sam Brannen
                Last updater:
                Sam Brannen
              • Votes:
                8 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  4 years, 35 weeks ago