跳到正文
cccskills
免费在 GitHub 公开

test-driven-generation

Generate implementation code that passes existing unit tests. Use when the user provides test files (Python pytest/unittest, Java JUnit/TestNG) and asks Claude to implement the code to make those tests pass. Supports full TDD workflow - analyzing tests, generating implementation, running tests, debugging failures, and iterating until all tests pass.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md4.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Test-Driven Generation

Generate implementation code that satisfies existing unit tests through an iterative test-driven development workflow.

Workflow

1. Analyze Tests

Read and understand the provided test file(s):

  • Identify what functions/classes/methods need to be implemented
  • Extract input/output expectations from assertions
  • Note edge cases, error conditions, and special behaviors
  • Understand dependencies and imports

2. Generate Implementation

Create implementation code that should satisfy the tests:

For Python:

  • Match the exact function/class signatures expected by tests
  • Implement logic to satisfy assertions
  • Handle all tested edge cases
  • Add necessary imports and dependencies

For Java:

  • Match exact method signatures and return types
  • Implement logic within the correct class structure
  • Handle exceptions as tested
  • Add required imports and annotations

3. Run Tests

Execute the test suite to verify the implementation:

Python:

pytest <test_file>.py -v
# or
python -m unittest <test_file>.py -v

Java:

mvn test
# or
gradle test
# or for single test file
javac <TestFile>.java && java org.junit.runner.JUnitCore <TestFile>

4. Debug Failures

If tests fail, analyze the failure output:

  • Read the assertion error messages carefully
  • Identify which specific test cases are failing
  • Understand what the test expected vs. what was returned
  • Locate the bug in the implementation

5. Iterate

Fix the implementation based on failure analysis:

  • Update the code to handle the failing case
  • Re-run tests to verify the fix
  • Repeat until all tests pass

Best Practices

Code Quality

  • Write clean, readable implementation code
  • Use descriptive variable names
  • Add comments for complex logic
  • Follow language conventions (PEP 8 for Python, Java naming conventions)

Test Understanding

  • Read ALL test cases before implementing
  • Don't assume - verify exact expected behavior from assertions
  • Pay attention to parametrized tests and edge cases
  • Check test fixtures and setup methods for context

Debugging Strategy

  • Start with the first failing test
  • Fix one test at a time when possible
  • After each fix, run the full suite to catch regressions
  • If stuck, re-read the test to verify understanding

Common Pitfalls

  • Type mismatches: Ensure return types match exactly (e.g., int vs float, List vs array)
  • Off-by-one errors: Carefully check boundary conditions
  • Null/None handling: Implement null checks if tests verify null behavior
  • Exception types: Raise/throw the exact exception type the test expects
  • Mutable state: Reset state between test runs if using class-level variables

Example Session

User provides test_calculator.py:

import pytest
from calculator import Calculator

def test_add():
    calc = Calculator()
    assert calc.add(2, 3) == 5
    assert calc.add(-1, 1) == 0

def test_divide():
    calc = Calculator()
    assert calc.divide(10, 2) == 5
    with pytest.raises(ValueError):
        calc.divide(10, 0)

Step 1: Analyze - need Calculator class with add() and divide() methods, divide should raise ValueError on zero

Step 2: Generate calculator.py:

class Calculator:
    def add(self, a, b):
        return a + b

    def divide(self, a, b):
        if b == 0:
            raise ValueError("Cannot divide by zero")
        return a / b

Step 3: Run pytest test_calculator.py -v

Step 4: If failure occurs, read error and identify issue

Step 5: Fix and re-run until passing

Language-Specific Notes

Python

  • Use type hints when test imports suggest them
  • Match pytest vs unittest assertion styles
  • Check for setUp/tearDown or fixtures that provide context
  • Watch for @pytest.mark.parametrize for multiple test cases

Java

  • Match access modifiers (public/private/protected)
  • Implement interfaces if tests verify interface compliance
  • Use correct exception handling (throws vs try-catch)
  • Check for @Before/@After setup methods
  • Watch for @ParameterizedTest annotations

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2562026年8月21日 更新

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2562026年8月21日 更新

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2562026年8月21日 更新

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2562026年8月21日 更新

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2562026年8月21日 更新

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

中文简介正在准备中。当前显示原文说明。

ArabelaTso/Skills-4-SE2562026年8月21日 更新

查看 ArabelaTso 的全部技能

报告此技能的问题