Recall & Review
beginner
What is a test container in database testing?
A test container is a lightweight, disposable instance of a database or service that runs in a container during tests. It helps create a real environment for testing without affecting the developer's machine or production data.
Click to reveal answer
intermediate
Why use test containers instead of an in-memory database for testing?
Test containers run the actual database software in a container, providing a more realistic environment. In-memory databases may behave differently from real databases, so test containers catch issues that only appear in real setups.
Click to reveal answer
intermediate
How do you start a PostgreSQL test container in JUnit 5?
You use the @Testcontainers annotation on the test class and define a static PostgreSQLContainer<?> field with @Container. The container starts before tests and stops after.Click to reveal answer
beginner
What is the benefit of using @Container annotation in JUnit tests?
The @Container annotation manages the lifecycle of the container automatically, starting it before tests and stopping it after, so you don't have to write manual setup or teardown code.
Click to reveal answer
advanced
What should you consider about test container resource usage?
Test containers use system resources like CPU, memory, and disk. Running many containers or large databases can slow tests. It's good to reuse containers or limit parallel tests to keep tests fast.
Click to reveal answer
What does a test container provide in database testing?
✗ Incorrect
Test containers run the actual database software inside a container, providing a real instance for testing.
Which annotation in JUnit 5 is used to mark a test container field?
✗ Incorrect
The @Container annotation marks a container field to be managed by JUnit 5 lifecycle.
Why might test containers be preferred over in-memory databases?
✗ Incorrect
Test containers run the real database software, giving a more accurate test environment.
What happens to a test container after the tests finish?
✗ Incorrect
Test containers are stopped and removed automatically to keep the environment clean.
Which of these is a common database supported by test containers?
✗ Incorrect
PostgreSQL is widely supported and commonly used with test containers.
Explain how test containers improve database testing compared to traditional methods.
Think about how real environment and isolation help testing.
You got /4 concepts.
Describe the steps to set up a PostgreSQL test container in a JUnit 5 test class.
Focus on annotations and container lifecycle.
You got /4 concepts.