Spring boot, using H2 bank for testing

Asked

Viewed 26 times

0

I use postgresql, but for the tests I want to use the H2 database, how do I make spring recognize the H2 database for the tests? Create another application.properties by passing the H2 data? ***I’m using mybatis instead of JPA

spring.h2.console.path=/h2-console

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver ```
  • Enter the @Activeprofiles("test") annotation in your test class

1 answer

0

You can create a file .properties with the acronym -dev, so you can indicate the profile at the time of running your project.

Example:

Maven

mvn spring-boot:run -Dspring-boot.run.profiles=dev

See also: how-to-use-spring-boot-profiles

Browser other questions tagged

You are not signed in. Login or sign up in order to post.