java试图在Spring启动测试属性配置上运行测试
我有一个通常在Postgres DB上运行的Spring启动应用程序,但是我想在嵌入式H2 DB上测试一些功能。
我尝试过用@TestPropertySource
注释我的测试类,并且尝试过创建测试和开发概要文件(单独的application.properties文件),但这些似乎都不起作用
这是我的应用测试。性质
server.port=8080
spring.resources.add-mappings=true
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.default_schema=public
随附我的测试数据。sql脚本:
insert into people(first_name, last_name, id) values('John', 'Johnson', 8);
insert into vehicles(name, make) values ('Mustang', 'Ford');
然而,即使我这样注释我的测试类:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Main.class)
@TestPropertySource(locations = {"classpath:application-test.properties"})
它仍然尝试使用常规Postgres DB运行应用程序,并且正在使用Postgres DB数据。sql而不是上面指定的sql。如果我切换常规数据。sql与test one一起出现如下错误:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
还有其他方法吗?我所能找到的任何解决办法都不适合我
共 (0) 个答案