Skip to content

Provide meta-annotation support for test-related annotations [SPR-7827] #12483

Closed
@spring-projects-issues

Description

@spring-projects-issues

Sam Brannen opened SPR-7827 and commented

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

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

Further Resources


Affects: 3.0.5

Issue Links:

Referenced from: commits 5e7021f, 2bd5a53, 412f74f

8 votes, 11 watchers

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions