3
我想用Spring Boot测试一个存储库,并且想要包含TestEntityManager来检查存储库是否确实应该做什么。使用@DataJpaTest设置自定义方案
这是JUnit测试:
@RunWith(SpringRunner.class)
@DataJpaTest
public class MyRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private MyRepository repository;
...
对于其他JUnit测试我有,设置了一些表,索引,序列和约束的架构中的application-junit.properties文件:
spring.datasource.url=jdbc:h2:mem:testdb;Mode=Oracle;INIT=create schema if not exists testdb\\;SET SCHEMA testdb\\;runscript from 'classpath:create.h2.sql';
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.platform=h2
spring.jpa.hibernate.ddl-auto=none
spring.datasource.continue-on-error=true
#datasource config
spring.database.driver-class-name=org.h2.Driver
spring.database.jndi-name=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
现在,用DataJpaTest这个配置似乎没有被使用。即使我添加@ActiveProfiles(“junit”)。
如何使JUnit测试使用我的create.h2.sql文件来设置表?
由于提前, 尼娜