Bird
0
0

In a Spring Boot test using Testcontainers, what happens if you forget to annotate the container field with @Container?

medium📝 component behavior Q5 of 15
Spring Boot - Testing Spring Boot Applications
In a Spring Boot test using Testcontainers, what happens if you forget to annotate the container field with @Container?
AThe container will not start automatically before tests
BThe container will start but not stop after tests
CThe test will fail to compile
DThe container will start twice
Step-by-Step Solution
Solution:
  1. Step 1: Role of @Container annotation

    @Container tells Testcontainers to manage the container lifecycle automatically.
  2. Step 2: Effect of missing @Container

    Without @Container, the container is just a normal object and won't start automatically before tests.
  3. Final Answer:

    The container will not start automatically before tests -> Option A
  4. Quick Check:

    Missing @Container = no auto start [OK]
Quick Trick: Always use @Container to auto start containers [OK]
Common Mistakes:
  • Assuming container starts without @Container
  • Expecting compile errors for missing annotation
  • Thinking container stops incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes