Java 在现有mysql数据库上执行Spring引导集成测试
我使用的是spring boot 2,我试图通过创建带有注释的测试来对存储库执行集成测试:Java 在现有mysql数据库上执行Spring引导集成测试,java,mysql,spring,spring-boot,integration-testing,Java,Mysql,Spring,Spring Boot,Integration Testing,我使用的是spring boot 2,我试图通过创建带有注释的测试来对存储库执行集成测试: @RunWith(SpringRunner.class) @DataJpaTest public class SomeTest { @Autowired private TestEntityManager entityManager; @Autowired private SomeRepository repository; // CONTENT }
@RunWith(SpringRunner.class)
@DataJpaTest
public class SomeTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private SomeRepository repository;
// CONTENT
}
我有liquibase迁移,我希望这些测试在特殊的mysql数据库上运行。不过,SpringBoot默认情况下会尝试配置嵌入式h2数据库。从POM文件中删除h2依赖项后,我得到:
Failed to replace DataSource with an embedded database for tests. If you want an embedded database please put a supported one on the classpath or tune the replace attribute of @AutoconfigureTestDatabase
当我运行我的应用程序时,它运行得非常好,因为我已经用正确的数据库连接填充了application.yml
。然而,当我将application.yml添加到测试资源时,什么也没有发生
有人能告诉我如何正确配置这些测试以使用mysql数据库吗?
@DataJpaTest
使用@AutoConfigureTestDatabase
-尝试使用@autoconfiguretestymanager
和@AutoConfigureDataJpa
在应用程序中配置了数据源吗@DataJpaTest
使用@AutoConfigureTestDatabase
,默认情况下,它会替换您配置的数据库。您可以在测试类上使用@AutoConfigureTestDatabase(replace=replace.NONE)
覆盖它。