Skip to content
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

Tests fail when using spring-context-indexer [SPR-17545] #22077

Closed
spring-issuemaster opened this issue Nov 28, 2018 · 5 comments
Assignees

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 28, 2018

Jean-Pierre Bergamin opened SPR-17545 and commented

Test configurations are not considered anymore while running tests when the spring-context-indexer is used in the project. Out of the blue I assume that only the components in the spring.components file are loaded and test configurations are left alone - which breaks tests.

This very simple project shows this behaviour: https://github.com/ractive/spring-context-indexer

If you enable the spring-context-indexer in the build.gradle file, tests fail because not the testClock bean in the TestConfig class is used, but the actual clock bean defined in the Config class.


Reference URL: https://github.com/ractive/spring-context-indexer

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 28, 2018

Juergen Hoeller commented

This is more or less by design: You're only supposed to apply spring-context-indexer to production deployment units. Otherwise you'd have to create spring.components files for your test codebase as well..

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 28, 2018

Jean-Pierre Bergamin commented

Ok I see. Although I think this makes this feature very hard to use. I cannot imagine a (simple) CI/CD setup that allows you to do that: running tests without the {{spring-context-indexer}} dependency but using it to build the deployment artifact.
Is there some sample project that shows how to set something up like this in gradle?

The other approach would be some way to suppress using the spring.components file in tests - which would simplify CI/CD setup of course.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 29, 2018

Stéphane Nicoll commented

I am not sure I got that Juergen Hoeller.

Jean-Pierre Bergamin your build setup is broken, spring-context-indexer does not kick in for src/test/java and it should if you intend to use classpath scanning in your tests (I'd argue this is a bad idea but that's probably a different discussion).

I don't know how to configure Gradle to let it run on your tests but that's not really something we can help you with here. When you enable the indexer, all your assets must use the indexer given that, as you've noticed, regular component scan will be switched off in presence of such file.

I've quickly tried with a maven project and spring.components are created in both target directories. Please consider revisiting your gradle.build. I also suggest we close this issue for now.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 29, 2018

Jean-Pierre Bergamin commented

Ah. In gradle you need to explicitely set testCompileOnly as well as gradle does not inherit compileOnly dependencies in tests.

Now it works: ractive/spring-context-indexer@6023579

It would be nice to put a word about that in the documentation: https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-scanning-index

 

I don't know how to configure Gradle to let it run on your tests

As simple as ./gradlew tests ;)

Feel free to close this ticket.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 29, 2018

Juergen Hoeller commented

Stéphane Nicoll, that's essentially what I meant: either only apply it to your production deployment, or add the indexer to your test codebase as well.

In any case, good to hear it's sorted out now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.