Questions tagged [testcontainers]

TestContainers is a Java library that supports (JUnit) tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

Testcontainers is an open source framework for providing throwaway, lightweight instances of databases, message brokers, web browsers, or just about anything that can run in a Docker container.

Define your test dependencies as code, then simply run your tests and containers will be created and then deleted.

https://www.testcontainers.org/

881 questions
74
votes
14 answers

Test Container test cases are failing due to "Could not find a valid Docker environment"

I am very new to using test containers. My test is failing with below exception. Running com.mastercard.example.testcontainers.testcontainersexampple.DemoControllerTest 2020-04-08 14:27:08.441 INFO --- [ main]…
Ketan
  • 2,612
  • 5
  • 31
  • 44
40
votes
6 answers

How to reuse Testcontainers between multiple SpringBootTests?

I'm using TestContainers with Spring Boot to run unit tests for repositories like this: @Testcontainers @ExtendWith(SpringExtension.class) @ActiveProfiles("itest") @SpringBootTest(classes =…
Martin Schröder
  • 4,176
  • 7
  • 47
  • 81
28
votes
7 answers

java.lang.IllegalStateException: Could not connect to Ryuk at localhost:49167

I am using test containers library to launch a container. It worked for a while but currently running into this java.lang.IllegalStateException: Could not connect to Ryuk at localhost:49167 at…
user1870400
  • 6,028
  • 13
  • 54
  • 115
28
votes
3 answers

Spring Boot TestContainers Mapped port can only be obtained after the container is started

I'm trying to add automated testing using the TestContainers library to my Spring Boot project Here is my test class to test my jpa repository: package com.ubm.mfi.repo; import com.ubm.mfi.domain.MasterFileIndexRow; import…
27
votes
6 answers

Populate a database with TestContainers in a SpringBoot integration test

I am testing TestContainers and I would like to know how to populate a database executing a .sql file to create the structure and add some rows. How to do it? @Rule public PostgreSQLContainer postgres = new PostgreSQLContainer();
jabrena
  • 1,166
  • 3
  • 11
  • 25
17
votes
5 answers

Testcontainers can't pull ryuk image: quay.io is not reachable

I have been experiencing issue with testcontainers failing to pull "ryuk" image from quay.io. [32m01:23:19.732[0;39m [35m[main][0;39m [39mDEBUG[0;39m [36mo.t.d.a.AuthDelegatingDockerClientConfig[0;39m - Effective auth config [null]…
Konstantin Pavlov
  • 956
  • 1
  • 10
  • 24
16
votes
5 answers

Testcontainers with Podman in Java tests

Is it possible to use Testcontainers with Podman in Java tests? As of March 2022 Testcontainers library doesn't detect an installed Podman as a valid Docker environment. Can Podman be a Docker replacement on both MacOS with Apple silicon (local…
Eugene Khyst
  • 9,236
  • 7
  • 38
  • 65
16
votes
2 answers

Mongo driver with @Testcontainers, throws exceptions after tests run successfully

I'm setting up integration tests in a sample spring boot kotlin project, using testcontainers:mongodb. I've set up a MongoDBContaine, and everything works as expected - the app connects to the mongodb and tests with repositories (e.g. save, delete)…
eja
  • 4,677
  • 3
  • 21
  • 30
14
votes
3 answers

testcontainers, hikari and Failed to validate connection org.postgresql.jdbc.PgConnection

I have a spring boot app. I'm testing it with testcontainers to ensure that the DB (postgres) and the Repository implementation do what they are supposed to do. I initialise the container with the following and works pretty well. @Container …
davide
  • 232
  • 2
  • 7
12
votes
2 answers

How to efficiently create Kafka topics with testcontainers?

I am using testcontainers.org with KafkaContainer. Currently, I use kafka-topics to create a topic after starting the container: kafkaContainer.execInContainer("/bin/sh", "-c", "/usr/bin/kafka-topics --create --zookeeper localhost:2181…
Jochen Christ
  • 697
  • 6
  • 13
12
votes
1 answer

Timed out waiting for container port to open (localhost ports: [32773] should be listening)

I am trying to use https://github.com/testcontainers/testcontainers-scala that is inherent from https://www.testcontainers.org/ as the following: final class MessageSpec extends BddSpec with ForAllTestContainer with BeforeAndAfterAll { …
softshipper
  • 32,463
  • 51
  • 192
  • 400
12
votes
1 answer

How to use local Docker image with testcontainers?

I want to use a local-only Docker image with testcontainers. The code looks like this: new GenericContainer("rserver:latest")... However it looks like another image with same name is fetched from a remote registry. How can I force testcontainers…
deamon
  • 89,107
  • 111
  • 320
  • 448
10
votes
1 answer

How to configure testcontainers to leave database container running if a test fails?

When using Test Containers the normal behavior is that it will shutdown the container when the test is finished due to pass or failure. Is there a way to configure test containers so that if a test fails the database container is kept around to help…
ams
  • 60,316
  • 68
  • 200
  • 288
10
votes
5 answers

Integration testing with Testcontainers + Quarkus + MongoDB

Trying out testcontainers for integration testing. I am testing rest api endpoint. Here is the technology stack - quarkus, RESTEasy and mongodb-client I am able to see MongoDB container is started successfully but getting exception. Exception:…
Tushar
  • 263
  • 3
  • 11
10
votes
3 answers

Spring testcontainers Driver org.testcontainers.jdbc.ContainerDatabaseDriver claims to not accept jdbcUrl

Having following configuration for my integration tests I ran into following exception: Driver org.testcontainers.jdbc.ContainerDatabaseDriver claims to not accept jdbcUrl,…
Tom
  • 192
  • 1
  • 1
  • 7
1
2 3
58 59