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
4
votes
1 answer

Fetching datasource properties in init function of testcontainers

I have configured test containers using jdbc url and trying to use init function to run flyway. Is there any example were the following is achieved. I am struggling to fetch the datasource properties dynamically in init function public class…
4
votes
2 answers

How do we do a purge of the database in between junit tests

Below are some of the classes that support @TestContainers functionality package com.changeorama.solidify; import static org.junit.Assert.assertTrue; import org.junit.jupiter.api.Test; .... @Testcontainers public class AbstractTest { …
4
votes
1 answer

How to add run arguments within docker test containers

For the particular image I am trying to run with test containers, it is required to start the container like so after building: docker run \ -v ~/volume:/tmp/volume\ --cap-add SYS_NICE --cap-add SYS_RESOURCE --cap-add SYS_PTRACE\ …
C. Dodds
  • 325
  • 3
  • 12
4
votes
2 answers

TestContainers, Spring Webflux, JUnit 5, MySQLR2DBCDatabaseContainer using @DynamicPropertySource

I'm trying to do the following; but using org.testcontainers.containers.MySQLR2DBCDatabaseContainer can anyone show me how this can be achieved, as MySQLR2DBCDatabaseContainer doesn't seem to have the following…
4
votes
1 answer

Reusing expensive beans in Spring Boot Tests

I am trying to improve performance of medium tests in Spring Boot. I am using the Spring Boot - testcontainers library. For an individual test this works really well, with a few annotations I can get access to kafka, zookeeper, and schema-registry.…
Michael
  • 3,498
  • 5
  • 27
  • 32
4
votes
2 answers

Mongo in testcontainers

I started playing with testcontainers and at the beginning of my journey I faced some issue (below). I did similar thing for mysql db and it worked fine. Do I miss some mongo specific config? According to [docs][1] there is not much to do. Thanks…
wacik93
  • 283
  • 1
  • 7
  • 16
4
votes
1 answer

How to get @Testcontainers(disabledWithoutDocker = true) behaviour in junit4/testcontainers

My codebase is ancient and is locked into JUnit4. I would like to integrate testcontainers with the project to incorporate docker containers in the automated tests. My dev box (which I control) runs docker, however, my CI system (which I do not…
spierepf
  • 2,774
  • 2
  • 30
  • 52
4
votes
3 answers

Is there a way to disable Testcontainers depending on Spring profile?

I am using Spring Boot and running tests in Testcontainers. Sometimes (when developing) I would like to run tests not against Testcontainers, but against already running containers. Is there a way to disable Testcontainers depending on Spring…
Skip
  • 6,240
  • 11
  • 67
  • 117
4
votes
4 answers

Run ES docker image with custom port using testcontainers

I want to run a container tests that running ES image via Docker. After some research I found https://www.testcontainers.org/ and they also have a built-it ES module. Because my development environment using ES in ports 9200 and 9300 I prefer to use…
AsfK
  • 3,328
  • 4
  • 36
  • 73
4
votes
1 answer

Exception: Mapped port can only be obtained after the container is started when using Spring `@DynamicPropertySource`

I tried to upgrade my tests to use TestConainers and Spring @DynamicPropertySource. @Container static Neo4jContainer neo4jContainer = new Neo4jContainer<>("neo4j:4.0") .withStartupTimeout(Duration.ofMinutes(5)); …
Hantsy
  • 8,006
  • 7
  • 64
  • 109
4
votes
1 answer

Testcontainers mongodb - Cluster description not yet available. Waiting for 30000 ms before timing out

I have basic Spring repository: @Repository public interface LRepository extends MongoRepository {} And I am using it inside a service: @Service @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class SerImpl { private…
tryingHard
  • 1,794
  • 4
  • 35
  • 74
4
votes
0 answers

How to override jna.tmpdir and java.io.tmpdir properties in testcontainers?

TestContainers have Native.java class, where it gets JNA props from "jna.tmpdir" key. How to override value of that key? like: jna.tmpdir=/data/builds/compose-tmp java.io.tmpdir=/data/builds/compose-tmp Part of code where it gets jna…
Seydazimov Nurbol
  • 1,404
  • 3
  • 10
  • 25
4
votes
1 answer

How to create apache spark standalone cluster for integration testing using TestContainers?

Is anyone knows how to create an apache-spark cluster for integration testing using testContainers https://www.testcontainers.org/ any running example please, i am struggling to find that.
Bravo
  • 8,589
  • 14
  • 48
  • 85
4
votes
1 answer

How to setup Localstack container not requiring credentials?

I have following code snippet, that is supposed to run in a AWS Lambda function: AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard().withRegion(AWS_REGION).build(); GetSecretValueRequest getSecretValueRequest = new…
4
votes
5 answers

Java Testcontainers - Cannot connect to exposed port

I implemented a POP3 server and client using javax.mail just to try doing integration testing with Docker. So I created two Docker images based on the openjdk:8-jre image and copied my jars to them and started it. Based on my configuration (see…
NoradX
  • 53
  • 1
  • 1
  • 6