Bird
0
0

Which of the following is the correct way to start a PostgreSQL Testcontainer in a Spring Boot test class?

easy📝 Syntax Q12 of 15
Spring Boot - Testing Spring Boot Applications
Which of the following is the correct way to start a PostgreSQL Testcontainer in a Spring Boot test class?
Astatic PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:latest").start();
BPostgreSQLContainer postgres = new PostgreSQLContainer("postgres:latest").run();
Cstatic PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:latest").begin();
DPostgreSQLContainer<?> postgres = new PostgreSQLContainer().start();
Step-by-Step Solution
Solution:
  1. Step 1: Check correct instantiation and start method

    The correct way is to create a static container with generic type and call start().
  2. Step 2: Validate options

    static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:latest").start(); uses correct syntax with generic type and start(). Others use wrong method names or miss generics.
  3. Final Answer:

    static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:latest").start(); -> Option A
  4. Quick Check:

    Use start() with generic type for Testcontainers [OK]
Quick Trick: Use start() method and generic type for containers [OK]
Common Mistakes:
  • Using .run() or .begin() instead of .start()
  • Omitting generic type
  • Not declaring container as static when needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes