Maven: <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers</artifactId> <version>1.16.0</version> <scope>test</scope> </dependency> Gradle: groovy testImplementation 'org.testcontainers:testcontainers:1.16.0' import org.junit.jupiter.api.Test; import org.testcontainers.containers.MySQLContainer; public class MySQLContainerTest { @Test public void testDatabase() { try (MySQLContainer mysql = new MySQLContainer<>("mysql:8.0.26")) { mysql.start(); String jdbcUrl = mysql.getJdbcUrl(); String username = mysql.getUsername(); String password = mysql.getPassword(); // ... } } } System.setProperty("testcontainers.docker.image.prefix", "your-docker-registry.com/"); System.setProperty("testcontainers.output.logLevel", "slf4j"); System.setProperty("testcontainers.startupTimeout", "60000");


上一篇:
下一篇:
切换中文