Analyze test coverage and add new test cases to improve coverage without changing implementation
Automatically analyzes test coverage reports and adds new test cases to improve coverage without modifying implementation. Activates when users mention coverage, testing, or ask to increase coverage percentages.
/plugin marketplace add teliha/dev-workflows/plugin install dev-workflows@dev-workflowsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
README.mdThis skill automatically activates when:
Detect project type and run appropriate coverage tool:
forge coverage --report summary
forge coverage --report lcov # For detailed report
npm run test:coverage
# or
jest --coverage
vitest --coverage
# or
npm run test:coverage
package.json scriptsAnalyze coverage report for:
Priority order for new tests:
Study existing tests and match:
// Good: Describes scenario and expected outcome
it('should return 401 when user is not authenticated', () => {})
it('should throw ValidationError when amount is negative', () => {})
// Bad: Vague or incomplete
it('works', () => {})
it('test error', () => {})
Follow Arrange-Act-Assert pattern:
it('should calculate total with discount', () => {
// Arrange
const cart = createCart([item1, item2]);
const discount = 0.1;
// Act
const total = cart.calculateTotal(discount);
// Assert
expect(total).toBe(expectedTotal);
});
// test/MyContract.t.sol
// Test successful case
function test_Deposit_Success() public {
uint256 amount = 1 ether;
vm.deal(user, amount);
vm.prank(user);
myContract.deposit{value: amount}();
assertEq(myContract.balances(user), amount);
}
// Test revert case
function test_RevertWhen_InsufficientBalance() public {
vm.prank(user);
vm.expectRevert(MyContract.InsufficientBalance.selector);
myContract.withdraw(1 ether);
}
// Test edge case
function test_Deposit_ZeroAmount() public {
vm.prank(user);
vm.expectRevert(MyContract.InvalidAmount.selector);
myContract.deposit{value: 0}();
}
// __tests__/api/users.test.ts
describe('GET /api/users', () => {
// Success case
it('should return users when authenticated', async () => {
mockAuth.mockResolvedValue({ user: testUser });
const res = await request(app).get('/api/users');
expect(res.status).toBe(200);
expect(res.body.data).toHaveLength(3);
});
// Error case
it('should return 401 when not authenticated', async () => {
mockAuth.mockResolvedValue(null);
const res = await request(app).get('/api/users');
expect(res.status).toBe(401);
});
// Edge case
it('should return empty array when no users exist', async () => {
mockDb.users.findMany.mockResolvedValue([]);
const res = await request(app).get('/api/users');
expect(res.body.data).toEqual([]);
});
});
// components/__tests__/Button.test.tsx
describe('Button', () => {
it('should render with text', () => {
render(<Button>Click me</Button>);
expect(screen.getByText('Click me')).toBeInTheDocument();
});
it('should call onClick when clicked', () => {
const onClick = jest.fn();
render(<Button onClick={onClick}>Click</Button>);
fireEvent.click(screen.getByText('Click'));
expect(onClick).toHaveBeenCalledTimes(1);
});
it('should be disabled when disabled prop is true', () => {
render(<Button disabled>Click</Button>);
expect(screen.getByRole('button')).toBeDisabled();
});
it('should show loading state', () => {
render(<Button loading>Click</Button>);
expect(screen.getByTestId('loading-spinner')).toBeInTheDocument();
});
});
Target coverage by area:
| Area | Target | Priority |
|---|---|---|
| Critical paths | 100% | Highest |
| Business logic | 90%+ | High |
| Utilities | 80%+ | Medium |
| UI components | 70%+ | Lower |
Focus on:
After adding tests:
Run all tests
# Foundry
forge test
# Jest/Vitest
npm test
Re-run coverage
# Foundry
forge coverage --report summary
# Jest
npm run test:coverage
Verify improvement
After adding tests:
## Coverage Improvement Summary
### Before
- Overall: 65%
- src/utils/: 45%
- src/api/: 70%
### After
- Overall: 78% (+13%)
- src/utils/: 85% (+40%)
- src/api/: 82% (+12%)
### Tests Added
1. `test/utils/format.test.ts` - 12 new tests
- Edge cases for date formatting
- Error handling for invalid inputs
2. `test/api/users.test.ts` - 8 new tests
- Unauthorized access tests
- Pagination edge cases
### Files Modified
- `test/utils/format.test.ts` (new)
- `test/api/users.test.ts` (modified)
### Verification
- [x] All tests pass
- [x] Coverage increased by 13%
- [x] No regressions
name: Improve Coverage
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # Weekly
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- uses: teliha/dev-workflows/.github/actions/improve-coverage@main
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
<!-- IMPROVE-COVERAGE:END -->This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.