Skip to content
Back to skills

Collection

ASecurity

测试开发专家,基于JUnit 5 + AssertJ + Mockito + JaCoCo的标准化测试规范。

  • 24 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 8, 2026
testingjavabashtesting

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-a778e554/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-a778e554)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: test-dev
description: 测试开发专家,基于JUnit 5 + AssertJ + Mockito + JaCoCo的标准化测试规范。
version: v1.0
tags: [testing, junit5, assertj, mockito, jacoco, coverage]
allowed-tools: Read, Write, Edit, Bash
requires-skills: []
---

# 测试开发

## 🎯 垂直职责
**单一职责**: 标准化测试框架 - JUnit 5 + AssertJ + Mockito + JaCoCo

## 📦 测试框架

### 依赖版本
```xml
<junit.version>5.11.3</junit.version>
<assertj.version>3.27.0</assertj.version>
<mockito.version>5.8.0</mockito.version>
<jacoco.version>0.8.12</jacoco.version>
```

### 覆盖率要求
| 模块 | 行覆盖率 | 分支覆盖率 |
|------|----------|------------|
| 核心引擎 | ≥90% | ≥85% |
| 指令实现 | ≥95% | ≥90% |
| **总体** | **≥85%** | **≥80%** |

## 📝 测试编写规范

### 命名规则
**格式**: `test{场景}_{期望结果}_when{条件}`

```java
// ✅ 好示例
void testIAddReturnsSum_whenStackHasTwoIntegers() { }
void testTypeCheckerRejectsInvalidBinaryOp_whenOperandsIncompatible() { }

// ❌ 差示例
void test1() { }
void testMethod() { }
```

### 测试结构 (Given-When-Then)
```java
@Test
@DisplayName("应正确执行 IADD 指令")
void testIAddInstruction() {
    // Given - 准备测试数据
    OperandStack stack = new OperandStack(10);
    stack.push(10);
    stack.push(20);

    // When - 执行被测操作
    instruction.execute(context);

    // Then - 验证结果
    assertThat(stack.pop()).isEqualTo(30);
}
```

### AssertJ断言
```java
// ✅ 推荐: AssertJ流畅断言
assertThat(result)
    .isNotNull()
    .isEqualTo(expected);

assertThat(list)
    .isNotEmpty()
    .hasSize(3);

// ❌ 避免: JUnit旧式断言
assertEquals(expected, result);  // 顺序易错
```

## 🎯 测试类型

### 单元测试
```java
@Tag("unit")
class InstructionTest {
    @Test
    @DisplayName("加法指令应正确计算")
    void testAdd() {
        // Given
        AddInstruction add = new AddInstruction();

        // When
        add.execute(context);

        // Then
        assertThat(result).isEqualTo(8);
    }
}
```

### 集成测试
```java
@Tag("integration")
class CompilerPipelineTest {
    @Test
    @DisplayName("完整编译流程应处理循环")
    void testFullCompilation() {
        // Given
        String source = loadTestProgram("fibonacci.cymbol");

        // When
        CompilationResult result = compiler.compile(source);

        // Then
        assertThat(result.isSuccess()).isTrue();
    }
}
```

### 参数化测试
```java
@ParameterizedTest
@ValueSource(ints = {0, 1, 10, 100})
@DisplayName("数据栈应处理各种值")
void testStackPushPop(int value) {
    stack.push(value);
    assertThat(stack.pop()).isEqualTo(value);
}
```

## 🛠️ 常用命令

```bash
# 运行测试
mvn test                                    # 全部测试
mvn test -pl ep21                           # 特定模块
mvn test -Dtest="*Optimizer*"              # 特定测试

# 覆盖率
mvn jacoco:report                          # 生成报告
open ep21/target/site/jacoco/index.html   # 查看报告
mvn jacoco:check                           # 检查覆盖率
```

## ⚠️ 常见问题

| 问题 | 原因 | 解决方案 |
|------|------|----------|
| 测试独立失败 | 共享静态状态 | 使用@BeforeEach初始化 |
| 测试有逻辑 | if/else分支 | 拆分成多个测试 |
| 覆盖率不足 | 缺少边界测试 | 添加边界条件测试 |

---
*版本: v1.0 | 垂直职责: 测试开发 | 2025-12-23*

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in testing →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.