This framework for test cases can be described as follows:
@Testcontainers: The annotation from the Testcontainers junit-jupiter module that hooks into the life cycle of a JUnit 5 test case.
@DataJpaTest: Spring Boot Test’s annotation we used in the previous section, indicating that all entity classes and Spring Data JPA repositories should be scanned.
@AutoConfigureTestDatabase: This Spring Boot Test annotation tells Spring Boot that instead of swapping out the DataSource bean like it normally does, to instead NOT replace it like it normally does when there’s an embedded database on the classpath (more on why this is needed shortly).
@Autowired VideoRepository: Injects the application’s Spring Data repository. We want the real thing and not some mock because this is what we’re testing!
@Container: Testcontainer’s annotation to flag this as the container to control through the JUnit life cycle.
PostgreSQLContainer: Creates a Postgres instance through Docker. The constructor string specifies the Docker Hub coordinates of the exact image we want. Note that this makes it easy to have multiple test classes, each focused on different versions of Postgres!
https://medium.com/javarevisited/database-integration-testing-with-testcontainers-8b4be2404a55