testcontainers
БесплатноБез исполняемых скриптовНе проверенTestcontainers for Docker-based integration testing in Java. Covers database containers, messaging systems, and Spring Boot @ServiceConnection. USE WHEN: user…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Testcontainers - Quick Reference
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:testcontainersfor comprehensive documentation.
When NOT to Use This Skill
- Unit Tests - Use
junitwith Mockito for fast isolated tests - REST API Tests Only - Use
rest-assuredwithout containers if API is mocked - Environments Without Docker - Use H2 or embedded databases
- CI with Limited Resources - Containers may be too heavy, use mocks
- Non-Java Projects - Check language-specific Testcontainers libraries
Setup Base
Maven Dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- Database specific -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<scope>test</scope>
</dependency>
Gradle Dependencies
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:postgresql")
testImplementation("org.testcontainers:mongodb")
@ServiceConnection (Spring Boot 3.1+)
Pattern Raccomandato
@SpringBootTest
@Testcontainers
class MyIntegrationTest {
@Container
@ServiceConnection
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:16-alpine");
@Test
void testWithDatabase() {
// Connection auto-configured
}
}
Container Supportati
| Container | Maven Artifact | Connection Details |
|---|---|---|
| PostgreSQLContainer | postgresql |
JDBC + R2DBC |
| MySQLContainer | mysql |
JDBC + R2DBC |
| MariaDBContainer | mariadb |
JDBC + R2DBC |
| MongoDBContainer | mongodb |
MongoConnectionDetails |
| KafkaContainer | kafka |
KafkaConnectionDetails |
| RedisContainer | - | RedisConnectionDetails |
| RabbitMQContainer | rabbitmq |
RabbitConnectionDetails |
| ElasticsearchContainer | elasticsearch |
ElasticsearchConnectionDetails |
| CassandraContainer | cassandra |
CassandraConnectionDetails |
GenericContainer con @ServiceConnection
@Container
@ServiceConnection(name = "redis")
static GenericContainer<?> redis =
new GenericContainer<>("redis:7-alpine")
.withExposedPorts(6379);
Lifecycle Management
Static Container (Shared across tests - RECOMMENDED)
@Testcontainers
class SharedContainerTest {
@Container
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:16-alpine");
@Test
void test1() { /* same container */ }
@Test
void test2() { /* same container */ }
}
Spring Bean Container (Best lifecycle control)
@TestConfiguration(proxyBeanMethods = false)
class TestContainersConfig {
@Bean
@ServiceConnection
PostgreSQLContainer<?> postgresContainer() {
return new PostgreSQLContainer<>("postgres:16-alpine");
}
}
@SpringBootTest
@Import(TestContainersConfig.class)
class ManagedContainerTest {
// Container lifecycle managed by Spring
// Started before beans, stopped after beans
}
Container Reuse (Development)
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:16-alpine")
.withReuse(true);
Richiede in ~/.testcontainers.properties:
testcontainers.reuse.enable=true
Database Containers
PostgreSQL
@Container
@ServiceConnection
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:16-alpine")
.withDatabaseName("testdb")
.withUsername("test")
.withPassword("test")
.withInitScript("init.sql");
MongoDB
@Container
@ServiceConnection
static MongoDBContainer mongo =
new MongoDBContainer("mongo:7.0")
.withSharding();
MySQL
@Container
@ServiceConnection
static MySQLContainer<?> mysql =
new MySQLContainer<>("mysql:8.0")
.withDatabaseName("testdb")
.withUsername("test")
.withPassword("test");
Messaging Containers
Kafka
@Container
@ServiceConnection
static KafkaContainer kafka =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.5.0"))
.withKraft();
RabbitMQ
@Container
@ServiceConnection
static RabbitMQContainer rabbitmq =
new RabbitMQContainer("rabbitmq:3.12-management")
.withExposedPorts(5672, 15672);
Redis
@Container
@ServiceConnection
static GenericContainer<?> redis =
new GenericContainer<>("redis:7-alpine")
.withExposedPorts(6379)
Установить testcontainers в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditFAQ
Что делает скилл testcontainers?
Testcontainers for Docker-based integration testing in Java. Covers database containers, messaging systems, and Spring Boot @ServiceConnection. USE WHEN: user mentions "testcontainers", "docker test", "integration test", asks about "@ServiceConnection", "PostgreSQLContainer", "MongoDBContainer", "test database", "docker compose test" DO NOT USE FOR: Unit tests - use `junit`; REST API tests - use `rest-assured`; Tests without Docker - use H2 or embedded databases; Non-Java projects - check language-specific tools
Как установить скилл testcontainers?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл testcontainers запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic