gpt4 book ai didi

java - JUnit 测试 POST 到参数化 API

转载 作者:行者123 更新时间:2023-12-02 08:49:36 24 4
gpt4 key购买 nike

如何将 {service} 传递给此 JUnit 测试?

@Test
public void test4() throws Exception {
List<ProofOfDeliveryUndeliveredResult> returnList = new ArrayList<ProofOfDeliveryUndeliveredResult>();
given(undeliveredQueryManager.prepareUndeliverServiceRecords(isA(UndeliveredRetrieveFilters.class),isA(String.class))).willReturn(ResponseEntity.ok().body(returnList));
String response = server.perform(MockMvcRequestBuilders.post("/api/{service}/retrieve").contentType(MediaType.APPLICATION_JSON).content("{\"startRetrieveTime\":\"\",\"endRetrieveTime\":\"\",\"timeStampFormat\":\"\"}"))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
assertEquals(response,"[]");
}

最佳答案

MockMvcRequestBuilderspost() 方法允许您传递可变参数列表,请参阅 javadoc 。提供的参数将按顺序替换到 URL 中。

server.perform(
MockMvcRequestBuilders
.post("/api/{service}/retrieve", "someservice")
.contentType(MediaTy...

关于java - JUnit 测试 POST 到参数化 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60870798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com