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

@ServiceConnection on a @Bean method does not work in sliced tests #36037

Closed
wants to merge 5 commits into from

Conversation

eddumelendez
Copy link
Contributor

Currently, in order to use @ServiceConnection in beans along with
slice test annotations @ImportAutoConfiguration(ServiceConnectionAutoConfiguration.class)
should be added to make it work. This commit register
ServiceConnectionAutoConfiguration in specific slice test annotations.

See gh-35252

Currently, in order to use `@ServiceConnection` in beans along with
slice test annotations `@ImportAutoConfiguration(ServiceConnectionAutoConfiguration.class)`
should be added to make it work. This commit register
`ServiceConnectionAutoConfiguration` in specific slice test annotations.

See spring-projectsgh-35252
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 23, 2023
@wilkinsona wilkinsona changed the title Support ServiceConnection beans in slice tests @ServiceConnection on a @Bean method does not work in sliced tests Jul 21, 2023
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 21, 2023
@wilkinsona wilkinsona added this to the 3.1.x milestone Jul 21, 2023
@wilkinsona
Copy link
Member

Thanks for the PR, @eddumelendez.

These changes introduce a cycle between spring-boot-testcontainers and spring-boot-test-autoconfigure:

  • the former has .imports files in src/main/resources for each of the sliced test annotations defined by the latter
  • the latter has tests that make use of @ServiceConnection which is defined by the former

I'm not sure how best to break this cycle. A couple of options:

  1. move all of the tests into spring-boot-testcontainers and remove the test dependency on spring-boot-testcontainers from spring-boot-test-autoconfigure
  2. merge the .imports files into those already in spring-boot-test-autoconfigure but this would require support for an import being "optional" as spring-boot-testcontainers wouldn't necessarily be on the classpath when using spring-boot-test-autoconfigure

1 feels the slightly better of these two options. There may also be others that I've overlooked. I'll discuss things with the team.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Jul 31, 2023
@wilkinsona wilkinsona modified the milestones: 3.1.x, 3.1.3 Aug 1, 2023
wilkinsona pushed a commit that referenced this pull request Aug 1, 2023
Previously, to use `@ServiceConnection` on a `@Bean` method in a sliced
test required ServiceConnectionAutoConfiguration to be imported using
`@ImportAutoConfiguration`. This commit removes the need for this
import by registering ServiceConnectionAutoConfiguration in specific
slice test annotations.

See gh-36037
@wilkinsona wilkinsona closed this in 0ad6878 Aug 1, 2023
@wilkinsona wilkinsona removed the for: team-attention An issue we'd like other members of the team to review label Aug 1, 2023
@wilkinsona
Copy link
Member

Thanks very much for the PR, @eddumelendez. In the end, we went with the second of the two options above. An entry in a .imports file can now be prefixed with optional:. An optional import that is not present on the classpath will be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants