Using Testcontainers and SQL Server to test Java projects on M1 Macs

Brian Schlining
2 min readOct 31, 2023

Testcontainers is fantastic project for spinning up throwaway, lightweight resources for testing. Unfortunately, if you are developing on recent Mac M1, M2, or M3 hardware, not all docker containers provide an AArch64 (aka arm64) image that will run natively on these CPUs. One example container that I frequently use is Microsoft’s SQL Server. My Mac will attempt to run the amd64 (intel) version of the SQL Server docker image via emulation, but that attempt always fails. Fortunately, the workaround is very straightforward. Microsoft provides both arm64 and amd64 docker images for its Azure SQL Edge database. For testing, Azure SQL Edge can be used as a drop-in replacement for SQL Server. Below, I’ve outlined the steps to use it for testing in your Java project.

1. Add Testcontainer dependencies

Gradle

testImplementation("org.testcontainers:jdbc:1.18.3")
testImplementation("org.testcontainers:mssqlserver:1.18.3")

Maven

<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>jdbc</artifactId>
<version>1.18.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mssqlserver</artifactId>…

--

--

Brian Schlining

Polyglot coder. Deep-sea Researcher. Zazen aficionado. I think squids are pretty cool.