title: Spring Rest Docs with JUnit 5 and Webflux
body: <p>I am unable to get a Spring Rest Docs test with JUnit 5 and Webflux working.</p>
  
  <p>I have a working integration test with <code>@WebFluxTest</code> like this:</p>
  
  <pre><code>@WebFluxTest(SomeController.class)
  class SomeControllerTest {
  
      @Autowired
      private WebTestClient testClient;
      @MockBean
      private SomeService service;
  
      @Test
      void testGetAllEndpoint() {
  
          when(service.getAll())
                  .thenReturn(List.of(new Machine(1,"Machine 1", "192.168.1.5", 9060)));
  
          testClient.get().uri("/api/machines")
                    .exchange()
                    .expectStatus().isOk()
                    .expectBodyList(Machine.class)
                    .hasSize(1);
      }
  }
  </code></pre>
  
  <p>I now want to write a documentation test. According to the docs, something like this should work:</p>
  
  <pre><code>@SpringBootTest
  @ExtendWith({RestDocumentationExtension.class, SpringExtension.class})
  class SomeControllerDocumentation {
  
      private WebTestClient testClient;
      @MockBean
      private SomeService service;
  
      @BeforeEach
      public void setUp(WebApplicationContext webApplicationContext,
                        RestDocumentationContextProvider restDocumentation) {
          this.testClient = WebTestClient.bindToApplicationContext(webApplicationContext)
                                         .configureClient()
                                         .filter(documentationConfiguration(restDocumentation))
                                         .build();
      }
  
      @Test
      void testGetAllEndpoint() {
  
          when(service.getMachines())
                  .thenReturn(List.of(new Machine(1, "Machine 1", "192.168.1.5", 9060)));
  
          testClient.get().uri("/api/machines")
                    .accept(MediaType.APPLICATION_JSON)
                            .exchange().expectStatus().isOk()
                            .expectBody().consumeWith(document("machines-list"));
      }
  }
  </code></pre>
  
  <p>I however get:</p>
  
  <pre><code>org.junit.jupiter.api.extension.ParameterResolutionException: 
  Failed to resolve parameter [org.springframework.web.context.WebApplicationContext webApplicationContext] 
  
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
  No qualifying bean of type 'org.springframework.web.context.WebApplicationContext' available: 
  expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
  </code></pre>
  
  <p>I am also wondering if <code>@SpringBootTest</code> is needed as annotation or if <code>@WebFluxTest(SomeController.class)</code> is also supposed to work.</p>
  
  <p>I am using Spring Boot 2.1.3 with <code>spring-restdocs-webtestclient</code> as dependency.</p>