I currently wrote a put request I wanted to test via WebTestClient. I followed some tutorials and adapted my case to it. Testing the request results in an error:
"NOSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.test.web.reactive.server.WebTestClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}"
I looked up some solutions on SO like this one: Cant autowire `WebTestClient` - no auto configuration but couldn't make it work, despite of the hints there.
Here is the test code:
@SpringBootTest
@AutoConfigureWebTestClient
public class DemonstratorApplicationTests {
private P4uServiceImpl p4uService = new P4uServiceImpl();
@Autowired
WebTestClient webTestClient;
@MockBean
ReqP4uAccount account;
@Test
void testPutAccount(){
ReqP4uAccount request = p4uService.buildRequest("testAccount");
this.webTestClient.put()
.uri("/account")
.contentType(MediaType.APPLICATION_JSON)
.body(request, ReqP4uAccount.class)
.exchange()
.expectStatus().isOk()
.expectBody(P4uAccount.class);
}
}
Has anyone an idea what's wrong with the test setup? Thx in advance