Bird
0
0

You wrote this test using Testcontainers but it fails with org.testcontainers.containers.ContainerLaunchException. What is the likely cause?

medium📝 Debug Q14 of 15
Spring Boot - Testing Spring Boot Applications
You wrote this test using Testcontainers but it fails with org.testcontainers.containers.ContainerLaunchException. What is the likely cause?
 @Container
 static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:latest");

 @Test
 void testDb() {
   // test code
 }
AThe PostgreSQL image name is incorrect
BThe container must be started manually with .start() in the test
CDocker is not running or accessible on the test machine
DTestcontainers do not support PostgreSQL
Step-by-Step Solution
Solution:
  1. Step 1: Understand ContainerLaunchException meaning

    This exception usually means Docker cannot start the container.
  2. Step 2: Check common causes

    Most common cause is Docker daemon not running or inaccessible to Testcontainers.
  3. Final Answer:

    Docker is not running or accessible on the test machine -> Option C
  4. Quick Check:

    ContainerLaunchException = Docker not running [OK]
Quick Trick: Check Docker daemon is running if container launch fails [OK]
Common Mistakes:
  • Thinking image name is wrong when it is correct
  • Trying to start container manually when @Container does it
  • Believing Testcontainers don't support PostgreSQL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes