Commit 6bd6279e authored by Madhura Bhave's avatar Madhura Bhave

Document slice test behavior with @Configuration classes

Closes gh-16274
parent 10e726ea
...@@ -7185,6 +7185,10 @@ NOTE: `@WebFluxTest` cannot detect routes registered via the functional web fram ...@@ -7185,6 +7185,10 @@ NOTE: `@WebFluxTest` cannot detect routes registered via the functional web fram
testing `RouterFunction` beans in the context, consider importing your `RouterFunction` testing `RouterFunction` beans in the context, consider importing your `RouterFunction`
yourself via `@Import` or using `@SpringBootTest`. yourself via `@Import` or using `@SpringBootTest`.
NOTE: `@WebFluxTest` cannot detect custom security configuration registered via a `@Bean`
of type `SecurityWebFilterChain`. To include that in your test, you will need to import
the configuration that registers the bean via `@Import` or use `@SpringBootTest`.
TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help you run TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help you run
<<boot-features-testing-spring-boot-applications-testing-with-running-server, <<boot-features-testing-spring-boot-applications-testing-with-running-server,
full end-to-end tests with an actual server>>. full end-to-end tests with an actual server>>.
...@@ -7813,6 +7817,34 @@ NOTE: Depending on the complexity of your application, you may either have a sin ...@@ -7813,6 +7817,34 @@ NOTE: Depending on the complexity of your application, you may either have a sin
approach lets you enable it in one of your tests, if necessary, with the `@Import` approach lets you enable it in one of your tests, if necessary, with the `@Import`
annotation. annotation.
Test slices exclude `@Configuration` classes from scanning. For example, for a `@WebMvcTest`,
the following configuration will not include the given `WebMvcConfigurer` bean in the application
context loaded by the test slice:
[source,java,indent=0]
----
@Configuration
public class WebConfiguration {
@Bean
public WebMvcConfigurer testConfigurer() {
return new WebMvcConfigurer() {
...
};
}
}
----
The configuration below will, however, cause the custom `WebMvcConfigurer` to be loaded
by the test slice.
[source,java,indent=0]
----
@Component
public class TestWebMvcConfigurer extends WebMvcConfigurer {
...
}
----
Another source of confusion is classpath scanning. Assume that, while you structured your Another source of confusion is classpath scanning. Assume that, while you structured your
code in a sensible way, you need to scan an additional package. Your application may code in a sensible way, you need to scan an additional package. Your application may
resemble the following code: resemble the following code:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment