# Java Testing Advanced

> Advanced testing - Testcontainers, contract testing, mutation testing, property-based

- **Type:** Skill
- **Install:** `agentstack add skill-linlannet-agent-skills-java-testing-advanced`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [linlannet](https://agentstack.voostack.com/s/linlannet)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [linlannet](https://github.com/linlannet)
- **Source:** https://github.com/linlannet/agent-skills/tree/main/skills/java-testing-advanced

## Install

```sh
agentstack add skill-linlannet-agent-skills-java-testing-advanced
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Java 高级测试技能

用于全面测试覆盖的高级测试技术。

## 概述

本技能涵盖高级测试模式，包括用于集成测试的 Testcontainers、使用 Pact 的契约测试、使用 PIT 的突变测试和基于属性的测试。

## 何时使用此技能

当您需要以下操作时使用：
- 使用真实数据库进行测试（Testcontainers）
- 验证 API 契约
- 使用突变测试发现测试漏洞
- 自动生成测试用例

## 快速参考

### Testcontainers

```java
@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();
    }
}
```

### 契约测试（Pact）

```java
@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");
    }
}
```

### 突变测试（PIT）

```xml

    org.pitest
    pitest-maven
    1.15.0
    
        
            com.example.service.*
        
        80
    

```

### 基于属性的测试

```java
@Property
void shouldReverseListTwiceReturnsOriginal(@ForAll List list) {
    Collections.reverse(list);
    Collections.reverse(list);
    // Original order restored
}
```

## 测试金字塔

```
     /\        E2E 测试（少量）
    /  \       契约测试
   /----\      集成测试
  /------\     单元测试（大量）
```

## 故障排除

| 问题 | 解决方案 |
|------|----------|
| 容器缓慢 | 重用容器 |
| 端口冲突 | 随机端口 |
| 不稳定的测试 | 等待策略 |

## 使用方法

```
Skill("java-testing-advanced")
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [linlannet](https://github.com/linlannet)
- **Source:** [linlannet/agent-skills](https://github.com/linlannet/agent-skills)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-linlannet-agent-skills-java-testing-advanced
- Seller: https://agentstack.voostack.com/s/linlannet
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
