Skip to content

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 first
  • fix: Bug fixes must include tests that reproduce the issue
  • refactor: Refactoring requires existing tests to pass
  • test: 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:

Terminal window
npm install -g @jeffallan/claude-skills

Or using Homebrew:

Terminal window
brew install claude-skills

After installation, I verify Test Master is available:

Terminal window
# Check available skills
claude-skills list
# Output shows available skills including test-master
test-master - Enforce test-driven development
commit - Create git commits
code-review - Review code quality

Test 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:

Terminal window
# Stage a new feature file
git add src/userService.js
# Try to commit without tests
git 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:

Terminal window
# Feature addition - requires tests
git commit -m "feat: add payment processing"
# Bug fix - requires reproduction test
git commit -m "fix: resolve race condition in cache"
# Refactoring - requires existing passing tests
git commit -m "refactor: simplify user authentication flow"
# Test addition - allowed without tests
git 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:

src/discount.js
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:

Terminal window
git add src/discount.js
git 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.js

Test Master prevents the commit. I must write tests first:

src/discount.test.js
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:

Terminal window
git add src/discount.js src/discount.test.js
git commit -m "feat: add discount calculation"
Test Master passed validation
Tests found: src/discount.test.js
Coverage will be checked after tests run

Example 2: Bug Fix with Test Master

I found a bug where the discount calculation doesn’t handle null membership:

Terminal window
# First, write a test that reproduces the bug
git add src/discount.test.js
src/discount.test.js
it('handles null membership gracefully', () => {
const user = { membership: null };
expect(() => calculateDiscount(user, 100)).not.toThrow();
expect(calculateDiscount(user, 100)).toBe(0);
});
Terminal window
# Run the test - it fails (RED)
npm test
# FAIL src/discount.test.js
# × handles null membership gracefully
# TypeError: Cannot read property 'membership' of null

Now I fix the implementation:

src/discount.js
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;
}
Terminal window
# Test passes (GREEN)
npm test
# PASS src/discount.test.js
# ✓ handles null membership gracefully
# Commit the fix
git add src/discount.js src/discount.test.js
git commit -m "fix: handle null membership in discount calculation"
Test Master validated bug fix with reproduction test

Example 3: Refactoring with Test Master

I want to simplify the discount logic using a map:

src/discount.js
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;
}
Terminal window
# Commit the refactor
git add src/discount.js
git commit -m "refactor: simplify discount calculation with rate map"
Test Master validated refactor
All existing tests still pass

Test Master allows the refactor because the existing test suite still passes. This gives me confidence the refactoring didn’t break anything.

Best Practices

Write the test first, see it fail, then implement:

Terminal window
# 1. Write failing test
# 2. Run test - fails (RED)
# 3. Write minimal implementation
# 4. Run test - passes (GREEN)
# 5. Refactor if needed (IMPROVE)
# 6. Commit

Commit tests and implementation together:

Terminal window
git add src/feature.js src/feature.test.js
git 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 exists
git add src/payment.js
git commit -m "feat: add payment"
Test Master Error: No tests found for payment.js

Don’t commit empty test files:

src/payment.test.js
// Empty test file - Test Master will reject this
describe('payment', () => {
// No tests
});

Don’t use generic commit messages:

Terminal window
# Bad - unclear what changed
git commit -m "update files"
# Good - specific change
git commit -m "feat: add Stripe payment integration"

Coverage Requirements

Test Master enforces 80% test coverage. After running tests, it checks the coverage report:

Terminal window
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% threshold

If coverage is below 80%:

Terminal window
-------------------|---------|----------|---------|---------|-------------------
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.js

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:

Terminal window
# View all available skills
claude-skills list
# Get help for specific skill
claude-skills help test-master
# Check Test Master status
claude-skills status test-master

Summary

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:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments