spring-projects / spring-restdocs

Test-driven documentation for RESTful services
https://spring.io/projects/spring-restdocs
Apache License 2.0
1.16k stars 734 forks source link

WebTestClient: Add AutoConfiguration for MockMvcWebTestClient? #897

Closed eiswind closed 11 months ago

eiswind commented 11 months ago

I just stumbled accross this when moving a test from MockMvc to MockMvcWebTestClient.

As far as I could see the AutoConfigureRestDocs for WebTestClient only works in a reactive web app. It's not a big deal, as I could workaround like

@ExtendWith(RestDocumentationExtension.class)
@WebMvcTest(CustomerApiController.class)
class CustomerApiControllerTest {

    private WebTestClient client;

    @Autowired
    MockMvc mockMvc;

    @BeforeEach
    public void setUp(RestDocumentationContextProvider restDocumentation) {
        this.client = MockMvcWebTestClient.bindTo(mockMvc).baseUrl("http://localhost")
                .filter(documentationConfiguration(restDocumentation))
                .build();
    }

Can you imagine providing something like this with the AutoConfiguration?

wilkinsona commented 11 months ago

Duplicates https://github.com/spring-projects/spring-restdocs/issues/691 and https://github.com/spring-projects/spring-boot/issues/35348.

eiswind commented 11 months ago

@wilkinsona Thanks for pointing me there. As for my use case this workaround seems to do what I need.