Configure SQL Server in memory (embedded) database for testing purpose in Spring

1.2k Views Asked by At

How do I configure my Spring Boot application so that when I run unit tests it will use embedded SQL Server so that stored procedures can be executed?

1

There are 1 best solutions below

2
Rohit Naik On

use spring boot jpa

compile('org.springframework.boot:spring-boot-starter-data-jpa')

have a application-local.yaml config

spring:
  datasource:
    driverClassName: org.h2.Driver
    username: sa
    password: password
    url: jdbc:h2:mem:testdb;MODE=MSSQLServer;DATABASE_TO_LOWER=TRUE

MODE can be any depending upon your dev or prod db to simulate the same.

add the following in build.gradle

bootRun {
    args = ["--spring.profiles.active=local"]
}