# Quarkus and Testcontainers

DevFeed: [Quarkus and Testcontainers](<https://devfeed.tech/articles/quarkus-and-testcontainers-18860.md>)

Original publisher: [Read original article](<https://www.morling.dev/blog/quarkus-and-testcontainers/>)

Published: 2020-11-28T16:45:00Z

Content type: tutorial

Language: en

Sources: [Gunnar Morling](<https://devfeed.tech/sources/gunnar-morling.md>)

Topics: [Quarkus](<https://devfeed.tech/topics/quarkus.md>), [Testcontainers](<https://devfeed.tech/topics/testcontainers.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Docker](<https://devfeed.tech/topics/docker.md>), [Object-relational mapping](<https://devfeed.tech/topics/orm.md>), [SQL](<https://devfeed.tech/topics/sql.md>)

Tags: [databases](<https://devfeed.tech/tags/databases.md>), [docker](<https://devfeed.tech/tags/docker.md>), [kafka](<https://devfeed.tech/tags/kafka.md>), [orm](<https://devfeed.tech/tags/orm.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [quarkus](<https://devfeed.tech/tags/quarkus.md>), [schema](<https://devfeed.tech/tags/schema.md>), [sql](<https://devfeed.tech/tags/sql.md>), [testcontainers](<https://devfeed.tech/tags/testcontainers.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

A tutorial on integrating Quarkus test resources with Testcontainers for JUnit tests. It explains the limitations of combining the Quarkus and Testcontainers JUnit extensions, recommends dynamically assigned Docker ports, and presents Quarkus test resources as an alternative for managing container lifecycles and database setup.

## Source excerpt

Table of Contents Bonus: Schema Creation The Testcontainers project is invaluable for spinning up containerized resources during your (JUnit) tests, e.g. databases or Kafka clusters. For users of JUnit 5, the project provides the @Testcontainers extension, which controls the lifecycle of containers used by a test. When testing a Quarkus application though, this is at odds with Quarkus' own @QuarkusTest extension; it's a recommended best practice to avoid fixed ports for any containers started by Testcontainers. Instead, you should rely on Docker to automatically allocate random free ports. This avoids conflicts between concurrently running tests, e.g. amongst multiple Postgres containers, started up by several parallel job runs in a CI environment, all trying to allocate Postgres' default port 5432. Obtaining the randomly assigned port and passing it into the Quarkus bootstrap process isn't possible though when combining the two JUnit extensions.