import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class GzzjyGatewayApplicationTests { @Autowired WebTestClient webTestClient; //判断请求是否异常 @Test public void a() throws Exception { webTestClient.get().uri("/xxx").exchange().expectStatus().isOk(); } //判断请求返回值是否正确 @Test public void b() throws Exception{ WebTestClient.BodyContentSpec bodyContentSpec= webTestClient.get().uri("/bbbbbb").exchange().expectStatus().isOk() .expectBody(); bodyContentSpec.jsonPath("$.current").exists();//判断json中路径current是否存在,相似的还有isNumber、isMap、isArray等判断方法。 String body=new String(bodyContentSpec.returnResult().getResponseBody(), Charset.forName("utf8"));//获取body进行判断处理 } }