From f78dcac56f074ab8ff038dd0c434ac4d9f22bd12 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 30 Oct 2023 11:12:25 +0000 Subject: [PATCH] Clarify that @AutoConfigureWebTestClient uses mock infrastructure Closes gh-29890 --- .../src/docs/asciidoc/features/testing.adoc | 2 +- .../web/reactive/AutoConfigureWebTestClient.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc index b98cacaad55..c395979803d 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc @@ -200,7 +200,7 @@ For convenience, tests that need to make REST calls to the started server can ad include::code:MyRandomPortWebTestClientTests[] -TIP: `WebTestClient` can be used against both live servers and <>. +TIP: `WebTestClient` can also used with a <>, removing the need for a running server, by annotating your test class with `@AutoConfigureWebTestClient`. This setup requires `spring-webflux` on the classpath. If you can not or will not add webflux, Spring Boot also provides a `TestRestTemplate` facility: diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java index 396a2d6a80d..02553bd5f3f 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2032 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,15 +26,18 @@ import java.time.Duration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.autoconfigure.properties.PropertyMapping; +import org.springframework.context.ApplicationContext; import org.springframework.test.web.reactive.server.WebTestClient; /** - * Annotation that can be applied to a test class to enable a {@link WebTestClient}. At - * the moment, only WebFlux applications are supported. + * Annotation that can be applied to a test class to enable a {@link WebTestClient} that + * is bound directly to the application. Tests do not rely upon an HTTP server and use + * mock requests and responses. At the moment, only WebFlux applications are supported. * * @author Stephane Nicoll * @since 2.0.0 * @see WebTestClientAutoConfiguration + * @see WebTestClient#bindToApplicationContext(ApplicationContext) */ @Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME)