1

我有一个应用程序,其中一个 api 是用 Get 方法定义的。它还需要请求主体,然后将其映射到 POJO。我正在尝试使用 webTestClient 测试这个控制器。但我没有看到使用 get() 方法发送请求正文的选项。不确定我是否以正确的方式定义我的 webTestClient。

我的控制器看起来像:

@GetMapping
public Flux<ResponseBody> getAllResources(@RequestBody Resource resource) {
//related code here...
}

我的测试方法:

@Test
public void myTest() {

webClient.get()
.uri("uri_path")
.header("Content-Type", "application/json")
.accept("application/json")
.exchange()
.expectedStatus.is2xxxSuccessful();
}

我在想,因为控制器中允许通过 get 调用将对象绑定到 POJO,所以应该有一些方法可以使用 webTestClient 对其进行测试。

4

1 回答 1

2

尝试使用:

webTestClient.method(HttpMethod.GET)

代替:

webTestClient.get()
于 2021-05-31T08:16:26.337 回答