-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
spring-test allows you to reference configuration classes that aren't annotated with @Configuration [SPR-9051] #13690
Comments
Aleksandr Dubinsky commented Also nested static Noticed this myself today. This doesn't have consistent behavior one way or another. Sure, it lets you quickly swap in a stub class. But why have this inflexible one-trick pony? Just make it an error rather than fix the inconsistencies. |
Keith Donald commented This is a pretty important issue to address from a user experience perspective. If you forget Please enforce that |
Joris Kuipers commented My code is actually relying on this behavior: I'm using inner config classes in my test code not annotated with |
Keith Donald commented I guess you haven't run into problems yet because the bean lifecycle is not invoked, consider yourself lucky. |
Sam Brannen commented Hi Aleksandr,
Nested static So if this is not the behavior you are experiencing, could you please put together a minimal working example project (or classes) that reproduces the unexpected behavior? Thanks, Sam |
Sam Brannen commented Hi guys, Based on tests I just checked in, I cannot reproduce the claims raised in this issue. Specifically, This is in line with Joris' comments. Specifically, classes that are declared via Thus I concur with Joris that the JavaDoc and Reference Manual for this support is misleading: the documentation typically refers to configuration classes when it should in fact refer to (and explain) annotated classes. This will be addressed in a #14037.
Thanks, Sam |
Sam Brannen commented Resolving this issue since I could not reproduce the claimed improper behavior. |
Keith Donald commented I provided a use case -- |
Sam Brannen commented Hi Keith, I'm not trying to put the onus on you per se; I'm just trying to ensure that the code works as expected. I believe that the tests I checked in demonstrate the expected behavior, but that of course may not cover enough use cases. That's why I'd like to see a failing use case so that I can assess if it's just a configuration error (perhaps due to a misunderstanding and/or misleading documentation) or rather a true bug in the framework.
We certainly want to do the best we can to support the user experience, but enforcing that
I'd really like to see at least a small code and configuration snippet to understand what your set up is there. Thanks, Sam |
Keith Donald commented It's a simple test to reproduce the problem I experienced. I assumed it might be a specific instance of a more general problem that had something to do with Spring bean lifecycle not being managed properly in a context text environment, but I may have been mistaken. In any case, there is a definite, easily reproducible specific problem (despite the fact I don't know what the cause is--I have not had a chance to investigate the code). To reproduce: Take a Transactional test that mutates the database:
"testInsert" should do something like assert the row isn't there, then insert the row, then verify the row is there, then rollback. If the referenced Spr9051TestsConfig class is annotated with Is this enough or do you need me to go to Github and submit a project you can clone and run? I just verified the problem again in my local environment. I can do a Skype screen-share as well; whatever, I'm easy to reach. |
Keith Donald commented Just a bump. Please advise if you need any more info :) |
Sam Brannen commented Hi Keith, Thanks for the details of the use case. I think that should be enough to go on for now, and I'll try to take a look at that today. Cheers, Sam |
Sam Brannen commented Hi guys, Based on Keith's use case, I put together some tests that investigate the issue. You can find details about my findings in the message of this commit. These are the tests involved:
Pay attention to the JavaDoc and NOTEs in the code, especially with regard to the the data sources in Based on the assumption that Keith's use case is similar, my conclusion is that the use of such annotated classes in configuration lite mode is not a bug in Spring Core or the TestContext Framework but rather a configuration error. Of course, as previously mentioned, this could potentially be a rather common configuration error, and #14037 will hopefully help to alleviate such errors in testing scenarios. I'd also like to point out that similar configuration errors can occur in production code. So this scenario is not limited to integration tests.
Thanks! Sam |
Keith Donald commented Ok, so because I forgot I agree forgetting |
Chris Beams commented I never advocate the use of "lite" mode. It is literally there as an escape hatch for people who really don't want a CGLIB dependency. Beyond that, it is simply a less functional version of "full" mode. There are no functional use cases where it is an advantage. |
Sam Brannen commented FYI: I added tests to verify proper scoping support for Just to clarify: beans created in lite mode do in fact get scoped. |
Sam Brannen commented If you are following this issue, you may also be interested in #14061. |
Keith Donald opened SPR-9051 and commented
When a
@ContextConfiguration
test class references a config class missing a@Configuration
annotation,@Bean
dependencies are wired successfully but the bean lifecycle is not applied (no init methods are invoked, for example). Adding the missing@Configuration
annotation solves the problem, however the problem and solution isn't obvious since wiring/injection appeared to work.It would be better if an integration test failed-fast if you reference a config class with no
@Configuration
annotation.Affects: 3.1 GA
Issue Links:
@Configuration
annotation will cause transaction not working ("is duplicated by")@Bean
'lite' mode and annotated classes in the reference manual@Configuration
@ContextConfiguration
#classes are not annotated with@Configuration
@Bean
'lite' mode and annotated class support in the TestContext Framework ("is superseded by")Referenced from: commits 500a4dd, 2017b24, 1cec0f9, 78c6d70
0 votes, 5 watchers
The text was updated successfully, but these errors were encountered: