import org.junit.jupiter.api.Test;
import org.testcontainers.containers.PostgreSQLContainer;
public class MyDatabaseTest {
private static final PostgreSQLContainer<?> postgresContainer = new PostgreSQLContainer<>("postgres:latest");
@BeforeAll
static void startContainer() {
postgresContainer.start();
}
@AfterAll
static void stopContainer() {
postgresContainer.stop();
}
@Test
public void testDatabaseConnection() {
}
}
@Test
public void testDatabaseConnection() throws SQLException {
String url = postgresContainer.getJdbcUrl();
String username = postgresContainer.getUsername();
String password = postgresContainer.getPassword();
Connection connection = DriverManager.getConnection(url, username, password);
connection.close();
}