Skip to main content
ClaudeWave
Skill85 estrellas del repoactualizado 3mo ago

coverage-enhancer

Analyze existing test suites and source code to suggest additional unit tests that improve test coverage. Use this skill when working with test files and source code to identify untested code paths, missing edge cases, uncovered branches, untested error conditions, and gaps in test coverage. Supports major testing frameworks (pytest, Jest, JUnit, Go testing, etc.) and generates targeted test suggestions based on coverage analysis.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE /tmp/coverage-enhancer && cp -r /tmp/coverage-enhancer/skills/coverage-enhancer ~/.claude/skills/coverage-enhancer
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

# Coverage Enhancer

Analyze existing tests and source code to identify coverage gaps, then suggest specific additional tests to improve overall test coverage and code quality.

## Core Capabilities

### 1. Coverage Gap Analysis

Identify untested areas in source code:
- **Uncovered lines** - Code never executed by tests
- **Uncovered branches** - Conditional paths not tested
- **Uncovered functions** - Methods/functions without tests
- **Missing error handling tests** - Exception paths not verified
- **Untested edge cases** - Boundary conditions not covered
- **Insufficient scenarios** - Limited test diversity

### 2. Existing Test Analysis

Understand current test coverage by:
- Parsing existing test files
- Identifying tested functions and methods
- Recognizing test patterns and frameworks
- Detecting coverage tools in use
- Analyzing test quality and completeness

### 3. Test Suggestion Generation

Generate specific, actionable test recommendations:
- Complete test code in the project's framework
- Clear test names describing what's being tested
- Setup, execution, and assertion steps
- Integration with existing test structure
- Prioritized by coverage impact

## Coverage Analysis Workflow

### Step 1: Analyze Existing Tests

Read and understand the current test suite:

**Identify test framework:**
```python
# pytest
def test_something():
    assert result == expected

# unittest
class TestSomething(unittest.TestCase):
    def test_method(self):
        self.assertEqual(result, expected)
```

**Map tested functionality:**
- Which functions/methods have tests?
- What scenarios are covered?
- What assertions are made?
- What inputs are tested?

**Identify test patterns:**
- Naming conventions
- Setup/teardown patterns
- Fixture usage
- Mock/stub patterns

### Step 2: Analyze Source Code

Examine the implementation to find gaps:

**Identify code paths:**
```python
def process(value):
    if value < 0:        # Branch 1
        raise ValueError
    elif value == 0:     # Branch 2
        return None
    else:                # Branch 3
        return value * 2
```

**Find untested branches:**
- If/else conditions not covered
- Switch/case statements
- Exception handlers (try/except/finally)
- Early returns
- Loop edge cases (zero iterations, one iteration, many)

**Identify uncovered functions:**
- Helper functions without tests
- Private methods (if testing them is valuable)
- Class methods and properties
- Static/class methods

### Step 3: Prioritize Coverage Gaps

Focus on high-value additions:

**Priority 1: Critical paths**
- Error handling and validation
- Security-sensitive code
- Data integrity operations
- Public API methods

**Priority 2: Complex logic**
- Conditional logic with multiple branches
- Loops with edge cases
- State transitions
- Algorithm implementations

**Priority 3: Completeness**
- Untested helper functions
- Missing edge cases
- Property getters/setters
- Simple utility functions

### Step 4: Generate Test Suggestions

Create specific, ready-to-use tests:

**Format:**
```python
# Suggested test for uncovered branch: negative input validation
def test_process_negative_input():
    """Test that negative values raise ValueError."""
    with pytest.raises(ValueError):
        process(-1)

# Reason: This tests the value < 0 branch which is currently uncovered
# Coverage impact: +5 lines, +1 branch
```

**Include:**
1. Test name (descriptive)
2. Test implementation (complete code)
3. Explanation of what's being tested
4. Coverage impact estimate
5. Integration notes (where to add in test file)

### Step 5: Suggest Coverage Tool Integration

Recommend running coverage analysis:

```bash
# Python
pytest --cov=mymodule --cov-report=html

# JavaScript
npm test -- --coverage

# Java
mvn test jacoco:report

# Go
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
```

## Coverage Analysis Patterns

### Pattern 1: Branch Coverage

**Uncovered code:**
```python
def calculate_discount(price, customer_type):
    if customer_type == "premium":
        return price * 0.8
    elif customer_type == "regular":
        return price * 0.9
    else:
        return price
```

**Existing test:**
```python
def test_calculate_discount_premium():
    assert calculate_discount(100, "premium") == 80
```

**Suggested additions:**
```python
def test_calculate_discount_regular():
    """Test discount calculation for regular customers."""
    assert calculate_discount(100, "regular") == 90
    # Coverage: Tests the 'regular' branch

def test_calculate_discount_no_discount():
    """Test that unknown customer types get no discount."""
    assert calculate_discount(100, "guest") == 100
    # Coverage: Tests the else branch

def test_calculate_discount_edge_cases():
    """Test discount calculation with edge case prices."""
    assert calculate_discount(0, "premium") == 0
    assert calculate_discount(0.01, "premium") == 0.008
    # Coverage: Tests edge cases within covered branches
```

### Pattern 2: Exception Path Coverage

**Uncovered code:**
```python
def divide(a, b):
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b
```

**Existing test:**
```python
def test_divide_normal():
    assert divide(10, 2) == 5
```

**Suggested addition:**
```python
def test_divide_by_zero():
    """Test that dividing by zero raises ValueError."""
    with pytest.raises(ValueError, match="Cannot divide by zero"):
        divide(10, 0)
    # Coverage: Tests the exception path (b == 0 branch)
    # Impact: +2 lines, +1 branch
```

### Pattern 3: Loop Coverage

**Uncovered code:**
```python
def find_max(numbers):
    if not numbers:
        return None

    max_val = numbers[0]
    for num in numbers[1:]:
        if num > max_val:
            max_val = num
    return max_val
```

**Existing test:**
```python
def test_find_max_normal():
    assert find_max([1, 5, 3, 2]) == 5
```

**Suggested additions:**
```python
def test_find_max_empty():
    """Test that empty list re
abstract-domain-explorerSkill

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.

abstract-invariant-generatorSkill

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.

abstract-state-analyzerSkill

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.

abstract-trace-summarizerSkill

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.

acsl-annotation-assistantSkill

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.

agent-browserSkill

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.

ambiguity-detectorSkill

Detects and analyzes ambiguous language in software requirements and user stories. Use when reviewing requirements documents, user stories, specifications, or any software requirement text to identify vague quantifiers, unclear scope, undefined terms, missing edge cases, subjective language, and incomplete specifications. Provides detailed analysis with clarifying questions and suggested improvements.

api-design-assistantSkill

Design and review APIs with suggestions for endpoints, parameters, return types, and best practices. Use when designing new APIs from requirements, reviewing existing API designs, generating API documentation, or getting implementation guidance. Supports REST APIs with focus on endpoint structure, request/response schemas, authentication, pagination, filtering, versioning, and OpenAPI specifications. Triggers when users ask to design, review, document, or improve APIs.