Reusable Containers (Experimental)

MS SQL Server Module

qianmoQqianmoQ· 更新于 2026-10-13· 阅读 5 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

MS SQL Server Module

Testcontainers module for MS SQL Server

Usage example

You can start a MS SQL Server container instance from any Java application by using:

Container definition

MSSQLServerContainer mssqlServer = new MSSQLServerContainer(
    "mcr.microsoft.com/mssql/server:2022-CU20-ubuntu-22.04"
)
    .acceptLicense()

EULA Acceptance

Due to licencing restrictions you are required to accept an EULA for this container image. To indicate that you accept the MS SQL Server image EULA, call the acceptLicense() method, or place a file at the root of the classpath named container-license-acceptance.txt, e.g. at src/test/resources/container-license-acceptance.txt. This file should contain the line: mcr.microsoft.com/mssql/server:2017-CU12 (or, if you are overriding the docker image name/tag, update accordingly).

Please see the microsoft-mssql-server image documentation for a link to the EULA document.

See Database containers for documentation and usage that is common to all relational database container types.

Testcontainers JDBC URL

jdbc:tc:sqlserver:2017-CU12:///databasename

See JDBC for documentation.

Adding this module to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

GradleMaven

testImplementation "org.testcontainers:testcontainers-mssqlserver:2.0.5"
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers-mssqlserver</artifactId>
    <version>2.0.5</version>
    <scope>test</scope>
</dependency>

Hint

Adding this Testcontainers library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency.

License

See LICENSE.

Copyright

Copyright (c) 2017 - 2019 G DATA Software AG and other authors.

See AUTHORS for contributors.

评论

登录后参与评论

正在加载评论…