java-testing-advanced by pluginagentmarketplace/custom-plugin-java
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-java --skill java-testing-advanced用于实现全面测试覆盖的高级测试技术。
本技能涵盖高级测试模式,包括用于集成测试的 Testcontainers、使用 Pact 的契约测试、使用 PIT 的突变测试以及基于属性的测试。
在您需要时使用:
@Testcontainers
@SpringBootTest
class OrderRepositoryIT {
@Container
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:15")
.withDatabaseName("test")
.withUsername("test")
.withPassword("test");
@Container
static KafkaContainer kafka =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0"));
@DynamicPropertySource
static void configure(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.kafka.bootstrap-servers", kafka::getBootstrapServers);
}
@Test
void shouldPersistOrder() {
Order saved = repository.save(new Order("item", 100.0));
assertThat(saved.getId()).isNotNull();
}
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
@ExtendWith(PactConsumerTestExt.class)
class UserServiceContractTest {
@Pact(consumer = "order-service", provider = "user-service")
public RequestResponsePact createPact(PactDslWithProvider builder) {
return builder
.given("user exists")
.uponReceiving("get user request")
.path("/users/1")
.method("GET")
.willRespondWith()
.status(200)
.body(new PactDslJsonBody()
.integerType("id", 1)
.stringType("name", "John"))
.toPact();
}
@Test
@PactTestFor(pactMethod = "createPact")
void testGetUser(MockServer mockServer) {
User user = client.getUser(mockServer.getUrl(), 1L);
assertThat(user.getName()).isEqualTo("John");
}
}
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.15.0</version>
<configuration>
<targetClasses>
<param>com.example.service.*</param>
</targetClasses>
<mutationThreshold>80</mutationThreshold>
</configuration>
</plugin>
@Property
void shouldReverseListTwiceReturnsOriginal(@ForAll List<Integer> list) {
Collections.reverse(list);
Collections.reverse(list);
// Original order restored
}
/\ E2E Tests (few)
/ \ Contract Tests
/----\ Integration Tests
/------\ Unit Tests (many)
| 问题 | 解决方案 |
|---|---|
| 容器启动慢 | 复用容器 |
| 端口冲突 | 使用随机端口 |
| 不稳定的测试 | 使用等待策略 |
Skill("java-testing-advanced")
每周安装量
136
代码仓库
GitHub 星标数
27
首次出现
2026年1月21日
安全审计
已安装于
opencode117
gemini-cli110
codex110
github-copilot99
cursor89
claude-code86
Advanced testing techniques for comprehensive test coverage.
This skill covers advanced testing patterns including Testcontainers for integration testing, contract testing with Pact, mutation testing with PIT, and property-based testing.
Use when you need to:
@Testcontainers
@SpringBootTest
class OrderRepositoryIT {
@Container
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>("postgres:15")
.withDatabaseName("test")
.withUsername("test")
.withPassword("test");
@Container
static KafkaContainer kafka =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0"));
@DynamicPropertySource
static void configure(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.kafka.bootstrap-servers", kafka::getBootstrapServers);
}
@Test
void shouldPersistOrder() {
Order saved = repository.save(new Order("item", 100.0));
assertThat(saved.getId()).isNotNull();
}
}
@ExtendWith(PactConsumerTestExt.class)
class UserServiceContractTest {
@Pact(consumer = "order-service", provider = "user-service")
public RequestResponsePact createPact(PactDslWithProvider builder) {
return builder
.given("user exists")
.uponReceiving("get user request")
.path("/users/1")
.method("GET")
.willRespondWith()
.status(200)
.body(new PactDslJsonBody()
.integerType("id", 1)
.stringType("name", "John"))
.toPact();
}
@Test
@PactTestFor(pactMethod = "createPact")
void testGetUser(MockServer mockServer) {
User user = client.getUser(mockServer.getUrl(), 1L);
assertThat(user.getName()).isEqualTo("John");
}
}
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.15.0</version>
<configuration>
<targetClasses>
<param>com.example.service.*</param>
</targetClasses>
<mutationThreshold>80</mutationThreshold>
</configuration>
</plugin>
@Property
void shouldReverseListTwiceReturnsOriginal(@ForAll List<Integer> list) {
Collections.reverse(list);
Collections.reverse(list);
// Original order restored
}
/\ E2E Tests (few)
/ \ Contract Tests
/----\ Integration Tests
/------\ Unit Tests (many)
| Problem | Solution |
|---|---|
| Container slow | Reuse containers |
| Port conflicts | Random ports |
| Flaky tests | Wait strategies |
Skill("java-testing-advanced")
Weekly Installs
136
Repository
GitHub Stars
27
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode117
gemini-cli110
codex110
github-copilot99
cursor89
claude-code86
通过 LiteLLM 代理让 Claude Code 对接 GitHub Copilot 运行 | 高级变通方案指南
36,300 周安装