We already have an example showing how to do it with MockMvc. It'd be good to have an equivalent example for WebTestClient. See https://github.com/spring-projects/spring-restdocs/issues/741 for some background.

Comment From: brneto

I just noticed an issue with this approach with my Spring Contract Testing. I'm investigating why first. I share it with you anyway.

I have a base contract base class that implements an abstract class where the RestAssureWebTestClient happens. e.g.

ContractBase:

abstract class ChassisBase extends ContractTest {

    @MockBean
    private Service service;

    @BeforeEach
    void setUp() {
        // init
        webTestClientSetup();

        // given
        var entity =
                new Entity()
                        .setId(1L)
                        .setName("test name")
                        .setDescription("description test");

        given(service.findAllItems())
                .willReturn(Flux.just(entity));
    }
}

AbstractContractTest (working):

@WebFluxTest
@AutoConfigureRestDocs
abstract class ContractTest {

    @Autowired
    private ApplicationContext context;

    @Autowired
    private WebTestClientRestDocumentationConfigurer configurer;

    void webTestClientSetup() {
        RestAssuredWebTestClient.webTestClient(
                WebTestClient
                        .bindToApplicationContext(context)
                        .configureClient()
                        .filter(configurer)
                        .entityExchangeResultConsumer(document("{class-name}/{method-name}"))
                        .build());
    }

AbstractContractTest (not working):

@WebFluxTest
@AutoConfigureRestDocs
abstract class ContractTest {

    @TestConfiguration
    static class RestDocsParameterizedOutput {

        @Bean
        WebTestClientBuilderCustomizer restDocsParameterizedOutput() {
            return builder -> builder.entityExchangeResultConsumer(document("{class-name}/{method-name}"));
        }
    }

    @Autowired
    private WebTestClient webClient;

    void webTestClientSetup() {
        RestAssuredWebTestClient.webTestClient(webTestClient);
    }

Comment From: wilkinsona

Closing in favor of #27755.