【发布时间】:2018-11-14 14:10:54
【问题描述】:
我有一个带有 spring data/jpa 的 SpringBoot 应用程序来连接数据库。
以及定义数据库连接的属性文件 yml。
一切都很好。
我创建了一个这样的测试:
@ActiveProfiles("dev")
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyMicroServiceApp.class, webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MyMicroServiceAppTest {
@Test
public <T> void postConnex() {
//Create Object connexCreate
...
// Create POST
ResponseEntity<Udsaconnex> result1 = this.restTemplate().postForEntity("http://localhost:" + port + "/v1/connex",
connexCreate, Udsaconnex.class);
id = result1.getBody().getIdconnex();
assertEquals(result1.getBody().toString().isEmpty(), false);
}
}
对于我的测试,我没有为数据库连接配置属性,但测试工作正常,我在控制台中查看:
休眠:如果存在则删除表连接
我不明白为什么,@SpringBootTest 像 @DataJpaTest 自动模拟数据库??
这是可能的,但我在 Spring Boot 文档中没有找到任何相关内容。
感谢您的帮助。
【问题讨论】:
标签: spring-boot spring-data-jpa spring-boot-test