-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Provide meta-annotation support for test-related annotations [SPR-7827] #12483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Neale Upstone commented That's the job. I recall having raised the issue of meta-annotations for JUnit a while back and it getting declined. Can't find it now. Prob pre-dates their shift to githubs issue tracking. |
Neale Upstone commented Just working on the JUnit end on this with aim of getting it merged in to 4.9, such that the above example would go further and add the On the Spring end, what you've identified for the test component is also applicable elsewhere, in that meta-annotations are inconsistently supported, which is not a good position to be in as a Spring user. I'd like to see the scope of this broadened to be that AnnotationUtils is used as widely as possible in place of Method.getAnnotation() and Class.getAnnotation(). |
Giovanni Dall'Oglio Risso commented I'm working on a project, whose architecture is plugin-structured, and the Application Context files are loaded with "classpath*:**/*-Context.xml" directive. The structure of the project is a "matrix":
In short: the library ext1-batch depends on all the others, but ext1-core and common-batch does not mix. So: I imagined this configuration, which makes use of meta-annotations described in this issue. @ContextConfiguration([...]) // config for HSQLDB environment
public @interface InRamEnvironment @ContextConfiguration([...]) // config for Oracle test environment
public @interface OracleEnvironment @ContextConfiguration([...]) // config for common-core part
public @interface CommonCoreIntegrationTest @ContextConfiguration([...]) // config for common-batch part
@CommonCoreIntegrationTest // decorating with common-core
public @interface CommonBatchIntegrationTest @ContextConfiguration([...]) // config for ext1-core part
@CommonCoreIntegrationTest // decorating with common-core
public @interface ExtOneCoreIntegrationTest @ContextConfiguration([...]) // config for ext1-batch part
@CommonBatchIntegrationTest // decorating with common-batch
@ExtOneCoreIntegrationTest // decorating with ext1-core
public @interface ExtOneBatchIntegrationTest @ExtOneBatchIntegrationTest
@InRamEnvironment
public class OneBatchTest {
[...]
} ...but to use this configuration, it is necessary set up the recognition of meta-annotations, at least for part of the So, I picked up your code, I developed the feature, and I allowed myself to make a pull request: #201 For the rest of the issue, I realize that there's more work to be done. In the meantime I would be grateful if you would consider my little addition, and make available this improvement as soon as possible, perhaps since the version 3.2 Thank you for the attention, and for your great framework... |
Neale Upstone commented Update on earlier JUnit link (although not strictly relevant to this. JUnit has moved repo to junit-team: so above link becomes junit-team/junit4#194). Also, above pull request has now been superceded by #219 |
Giovanni Dall'Oglio Risso commented My pull request is a year old. I would not bet a dollar that can be rebased without going crazy... If you agree to postpone this issue to the 4.0.RC2 (and give me a month), I would love to try to help. Thank you. |
Sam Brannen commented Giovanni Dall'Oglio Risso et al, I have in fact been working on this feature in my #12483 branch on GitHub. So feel free to track the progress there. Please note, however, that the current implementation is in line with the original intent of this issue: to allow test-related annotations to be used as meta-annotations within the TestContext framework (TCF). In other words, after this work is committed to Regards, Sam |
Sam Brannen commented This issue has been addressed as described in the comments for GitHub commit 2bd5a535e1.
|
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. SeeUserRepositoryIntegrationTests
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 specifySpringJUnit4ClassRunner
as the runner for each individual test class.Deliverables
Provide meta-annotation support for the following annotations within the context of the TestContext framework.
@ContextConfiguration
@WebAppConfiguration
@ContextHierarchy
@ActiveProfiles
@DirtiesContext
@TestExecutionListeners
@IfProfileValue
@ProfileValueSourceConfiguration
@Transactional
@BeforeTransaction
@AfterTransaction
@TransactionConfiguration
@Rollback
@Repeat
@Timed
Code Examples
Further Resources
Affects: 3.0.5
Issue Links:
Referenced from: commits 5e7021f, 2bd5a53, 412f74f
8 votes, 11 watchers
The text was updated successfully, but these errors were encountered: