Junior — Middle
Have you worked with the Testcontainers library in your last project?
sobes.tech AI
Answer from AI
Yes, in one of my recent projects, I used the Testcontainers library for integration testing. It allows running Docker containers with necessary services (such as a database or message broker) directly from tests, which simplifies environment setup and makes tests more reliable and isolated.
Example of usage with PostgreSQL:
@Testcontainers
public class MyRepositoryTest {
@Container
public static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:13")
.withDatabaseName("testdb")
.withUsername("user")
.withPassword("password");
@Test
void testDatabaseConnection() {
String jdbcUrl = postgres.getJdbcUrl();
// Use jdbcUrl for connection and repository testing
}
}