【发布时间】:2019-05-17 07:52:12
【问题描述】:
我正在使用 Springboot 和 Java 8
我有以下网址,与邮递员配合得很好:
“http://localhost:8888/gc/goods/getAll”
现在我试着写一个自动化测试:
@RunWith(SpringRunner.class)
@SpringBootTest
public class GCGoodControllerTest
{
@Test
public void getAllGoodsRequest()
{
RestTemplate restTemplate = new RestTemplate();
Object test = restTemplate.getForObject("http://localhost:8888/gc/goods/getAll", Object.class);
}
}
虽然 Postman 将所有数据返回给我,但我的测试中出现以下错误:
org.springframework.web.client.ResourceAccessException: I/O 错误 “http://localhost:8888/gc/goods/getAll”的 GET 请求:连接 拒绝:连接;嵌套异常是 java.net.ConnectException: 连接被拒绝:连接
如何在测试期间正确请求数据?
感谢您的帮助!
【问题讨论】:
-
你能在这里发布完整的堆栈跟踪吗?
-
感谢您抽出宝贵时间,但@pcoates 已经回答了这个问题!
标签: spring-boot testing resttemplate