【发布时间】:2019-02-19 11:29:34
【问题描述】:
我在 Spring Boot 上进行了单元测试:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class CustomerControllerIT {
private RestTemplate restTemplate = new RestTemplate();
@Test
public void findAllCustomers() throws Exception {
ResponseEntity<List<Customer>> responseEntity = restTemplate.exchange(
"http://localhost:8080/Customer", HttpMethod.GET, null,
new ParameterizedTypeReference<List<Customer>>() {
});
List<Customer> list = responseEntity.getBody();
Assert.assertEquals(list.size(), 0);
}
}
-
如果我在已启动的应用程序上启动测试 - 测试正常
-
如果我尝试仅启动 IT,则会出现连接被拒绝错误
我的application.properties 与单次启动相同。
用于测试并位于resources和testResources中。
Application.class 是:
@ComponentScan({"mypackage"})
@EntityScan(basePackages = {"mypackage.model"})
@EnableJpaRepositories(basePackages = {"mypackage.persistence"})
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
【问题讨论】:
标签: spring-boot junit integration-testing