How to Use Test Master Skill in Claude Code for Quality Development
Purpose
This post demonstrates how to use Test Master skill in Claude Code to enforce test-driven development practices and improve code quality.
Environment
- Claude Code with claude-skills plugin
- Node.js project with Jest/pytest frameworks
- Test coverage tools (Jest Coverture, pytest-cov)
What is Test Master?
Test Master is a skill in the claude-skills plugin that enforces test-driven development (TDD) workflow. When I invoke it, the skill requires me to write tests FIRST before implementing any features or fixing bugs. This ensures 80%+ test coverage and prevents skipping tests.
The skill has four enforcement rules:
feat: New features must have tests written firstfix: Bug fixes must include tests that reproduce the issuerefactor: Refactoring requires existing tests to passtest: Pure test additions are allowed directly
Installation and Setup
First, I need to install the claude-skills plugin. The plugin extends Claude Code with specialized skills for development workflows.
To install claude-skills:
npm install -g @jeffallan/claude-skillsOr using Homebrew:
brew install claude-skillsAfter installation, I verify Test Master is available:
# Check available skillsclaude-skills list
# Output shows available skills including test-master✓ test-master - Enforce test-driven development✓ commit - Create git commits✓ code-review - Review code qualityTest Master activates automatically when I use standard git commands like git commit. The skill analyzes staged files to determine if tests exist before allowing the commit.
Core Usage Patterns
Basic Invocation
I don’t need to manually invoke Test Master. It activates during git operations:
# Stage a new feature filegit add src/userService.js
# Try to commit without testsgit commit -m "feat: add user service"
# Test Master blocks the commit❌ Test Master Error: No tests found for src/userService.js Please write tests first before committing feature code.Supported File Types
Test Master recognizes test files by naming conventions:
- JavaScript:
*.test.js,*.spec.js - TypeScript:
*.test.ts,*.spec.ts - Python:
test_*.py,*_test.py - Go:
*_test.go
When I add a feature file like userService.js, Test Master looks for userService.test.js or userService.spec.js in the same directory.
Commit Message Detection
The skill parses commit messages to determine the type of change:
# Feature addition - requires testsgit commit -m "feat: add payment processing"
# Bug fix - requires reproduction testgit commit -m "fix: resolve race condition in cache"
# Refactoring - requires existing passing testsgit commit -m "refactor: simplify user authentication flow"
# Test addition - allowed without testsgit commit -m "test: add edge case coverage for login"Practical Examples
Example 1: Using Test Master for Feature Development
I need to add a new function to calculate user discounts. Let me create the feature file first:
export function calculateDiscount(user, total) { if (user.membership === 'gold') { return total * 0.2; } if (user.membership === 'silver') { return total * 0.1; } return 0;}When I try to commit this file:
git add src/discount.jsgit commit -m "feat: add discount calculation"
❌ Test Master blocked commit Reason: No test file found for src/discount.js Required: src/discount.test.js or src/discount.spec.jsTest Master prevents the commit. I must write tests first:
import { calculateDiscount } from './discount.js';
describe('calculateDiscount', () => { it('gives 20% discount for gold members', () => { const user = { membership: 'gold' }; expect(calculateDiscount(user, 100)).toBe(20); });
it('gives 10% discount for silver members', () => { const user = { membership: 'silver' }; expect(calculateDiscount(user, 100)).toBe(10); });
it('gives no discount for regular members', () => { const user = { membership: 'regular' }; expect(calculateDiscount(user, 100)).toBe(0); });});Now I commit both files together:
git add src/discount.js src/discount.test.jsgit commit -m "feat: add discount calculation"
✓ Test Master passed validation Tests found: src/discount.test.js Coverage will be checked after tests runExample 2: Bug Fix with Test Master
I found a bug where the discount calculation doesn’t handle null membership:
# First, write a test that reproduces the buggit add src/discount.test.jsit('handles null membership gracefully', () => { const user = { membership: null }; expect(() => calculateDiscount(user, 100)).not.toThrow(); expect(calculateDiscount(user, 100)).toBe(0);});# Run the test - it fails (RED)npm test
# FAIL src/discount.test.js# × handles null membership gracefully# TypeError: Cannot read property 'membership' of nullNow I fix the implementation:
export function calculateDiscount(user, total) { if (!user || !user.membership) { return 0; } if (user.membership === 'gold') { return total * 0.2; } if (user.membership === 'silver') { return total * 0.1; } return 0;}# Test passes (GREEN)npm test
# PASS src/discount.test.js# ✓ handles null membership gracefully
# Commit the fixgit add src/discount.js src/discount.test.jsgit commit -m "fix: handle null membership in discount calculation"
✓ Test Master validated bug fix with reproduction testExample 3: Refactoring with Test Master
I want to simplify the discount logic using a map:
const DISCOUNT_RATES = { gold: 0.2, silver: 0.1, regular: 0};
export function calculateDiscount(user, total) { if (!user || !user.membership) { return 0; } const rate = DISCOUNT_RATES[user.membership] || 0; return total * rate;}# Commit the refactorgit add src/discount.jsgit commit -m "refactor: simplify discount calculation with rate map"
✓ Test Master validated refactor All existing tests still passTest Master allows the refactor because the existing test suite still passes. This gives me confidence the refactoring didn’t break anything.
Best Practices
DO: Recommended Practices
Write the test first, see it fail, then implement:
# 1. Write failing test# 2. Run test - fails (RED)# 3. Write minimal implementation# 4. Run test - passes (GREEN)# 5. Refactor if needed (IMPROVE)# 6. CommitCommit tests and implementation together:
git add src/feature.js src/feature.test.jsgit commit -m "feat: add user authentication"Use descriptive test names:
it('rejects login with invalid password', () => { // Clear what this test does});
// Not this:it('test2', () => { // Unclear});DON’T: Common Mistakes
Don’t write the implementation first:
# Wrong: Implementation existsgit add src/payment.jsgit commit -m "feat: add payment"
❌ Test Master Error: No tests found for payment.jsDon’t commit empty test files:
// Empty test file - Test Master will reject thisdescribe('payment', () => { // No tests});Don’t use generic commit messages:
# Bad - unclear what changedgit commit -m "update files"
# Good - specific changegit commit -m "feat: add Stripe payment integration"Coverage Requirements
Test Master enforces 80% test coverage. After running tests, it checks the coverage report:
npm run test:coverage
# Test Master checks output-------------------|---------|----------|---------|---------|-------------------File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s-------------------|---------|----------|---------|---------|-------------------All files | 85.42 | 78.95 | 91.67 | 85.96 | discount.js | 100 | 100 | 100 | 100 | userService.js | 75 | 50 | 75 | 75 | 23,45-------------------|---------|----------|---------|---------|-------------------
✓ Coverage meets 80% thresholdIf coverage is below 80%:
-------------------|---------|----------|---------|---------|-------------------All files | 65.42 | 58.95 | 66.67 | 65.96 |-------------------|---------|----------|---------|---------|-------------------
❌ Test Master Error: Coverage is 65.96%, required minimum is 80% Please add tests for uncovered lines in userService.jsRelated Skills and Resources
Test Master works well with other claude-skills:
- code-review: Run after Test Master to check code quality
- commit: Both skills activate during git operations
- tdd-guide: Provides detailed TDD workflow guidance
Official resources:
# View all available skillsclaude-skills list
# Get help for specific skillclaude-skills help test-master
# Check Test Master statusclaude-skills status test-masterSummary
In this post, I showed how Test Master enforces test-driven development in Claude Code. The key point is that Test Master prevents commits without tests, requiring the TDD workflow: write tests first, implement second, refactor third. This ensures 80%+ coverage and maintains code quality throughout development.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
- 👨💻 claude-skills Documentation
- 👨💻 claude-skills GitHub Repository
- 👨💻 Claude Code Official Documentation
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments