Skip to content

Commit aaaafc6

Browse files
committed
Add a note about TestConfiguration, Import, and ordering
Closes gh-30513
1 parent dc645f0 commit aaaafc6

File tree

1 file changed

+5
-2
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/asciidoc/features

1 file changed

+5
-2
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,17 @@ Therefore, as long as your tests share the same configuration (no matter how it
142142
If your application uses component scanning (for example, if you use `@SpringBootApplication` or `@ComponentScan`), you may find top-level configuration classes that you created only for specific tests accidentally get picked up everywhere.
143143

144144
As we <<features#features.testing.spring-boot-applications.detecting-configuration,have seen earlier>>, `@TestConfiguration` can be used on an inner class of a test to customize the primary configuration.
145-
When placed on a top-level class, `@TestConfiguration` indicates that classes in `src/test/java` should not be picked up by scanning.
146-
You can then import that class explicitly where it is required, as shown in the following example:
145+
`@TestConfiguration` can also be used on a top-level class. Doing so indicates that the class should not be picked up by scanning.
146+
You can then import the class explicitly where it is required, as shown in the following example:
147147

148148
include::code:MyTests[]
149149

150150
NOTE: If you directly use `@ComponentScan` (that is, not through `@SpringBootApplication`) you need to register the `TypeExcludeFilter` with it.
151151
See {spring-boot-module-api}/context/TypeExcludeFilter.html[the Javadoc] for details.
152152

153+
NOTE: An imported `@TestConfiguration` is processed earlier than an inner-class `@TestConfiguration` and an imported `@TestConfiguration` will be processed before any configuration found through component scanning.
154+
Generally speaking, this difference in ordering has no noticeable effect but it is something to be aware of if you're relying on bean overriding.
155+
153156

154157

155158
[[features.testing.spring-boot-applications.using-application-arguments]]

0 commit comments

Comments
 (0)