我使用 spring boot 2.1.7.RELEASE 和 junit 5。不幸的是,@RestClientTest 有问题,因为我收到 java.lang.IllegalStateException: Unable to use auto-configured MockRestServiceServer since MockServerRestTemplateCustomizer has not being bound to a RestTemplate。您对如何正确配置有任何想法吗?
类似的代码在 junit 4 中完美运行。源代码基于文档https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html。
源代码:
@RestClientTest(RemoteVehicleDetailsService.class)
public class ExampleRestClientTest {
@Autowired
private RemoteVehicleDetailsService service;
@Autowired
private MockRestServiceServer server;
@Test
public void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails()
throws Exception {
this.server.expect(requestTo("/greet/details"))
.andRespond(withSuccess("hello", MediaType.TEXT_PLAIN));
String greeting = this.service.callRestService();
assertThat(greeting).isEqualTo("hello");
}
江户川乱折腾
繁华开满天机
相关分类