I am working with Springboot and Java 8
I have following url, that works pretty fine with postman:
"http://localhost:8888/gc/goods/getAll"
Now I have tried to write an automated test:
@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);
}
}
While Postman gives me all data back, I get following error from my test:
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8888/gc/goods/getAll": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
How do I request the Data correctly during testing?
Thanks for help!
Sounds like your server is not up and running on port 8888 when your automated test runs. If you need the test to start your embedded server you need to annotate the test class with something like
@SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT)