Search code examples
sql-serverspring-bootintegration-testingtestcontainersmssql-jdbc

How can i obtain a temporary mssql database with test containers using a specially modified JDBC URL?


I want to obtain a temporary mssql database to execute some tests, currently i am using h2 for the purpose but because it does not support stored procedures i want to start using the test containers, how can i obtain such database through the jdbc url in my application-test.yaml as i do for the h2:

spring:
  datasource:
    url: jdbc:h2:mem:master;MODE=MSSQLServer;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=FALSE;DB_CLOSE_ON_EXIT=false;CASE_INSENSITIVE_IDENTIFIERS=TRUE;TRACE_LEVEL_SYSTEM_OUT=2;INIT=CREATE SCHEMA IF NOT EXISTS dbo\;SET SCHEMA dbo

I tried to find a solution for this in the https://www.testcontainers.org/modules/databases/jdbc/ documentation but i dont find any for mssql.


Solution

  • Hostless JDBC url can be used. Using spring boot the following property should be set spring.datasource.url=jdbc:tc:sqlserver:latest:///. Read more about Testcontainers MSSQL server module.

    See an example here