home / skills / thebushidocollective / han / test

This skill helps you write tests using test-driven development principles to rapidly validate features and improve code quality.

npx playbooks add skill thebushidocollective/han --skill test

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.6 KB
---
name: test
description: Write tests for code using test-driven development principles

---

# test

## Name

han-core:test - Write tests for code using test-driven development principles

## Synopsis

```
/test [arguments]
```

## Description

Write tests for code using test-driven development principles

## Implementation

Write tests for the specified code or feature using test-driven development (TDD) methodology.

## Process

Follow TDD methodology:

1. **Understand the requirement**: Clarify what needs to be tested
2. **Write failing test first**: Create a test that fails because the feature doesn't exist yet
3. **Run the test**: Verify it fails for the right reason
4. **Implement minimal code**: Write just enough code to make the test pass
5. **Run test again**: Verify it now passes
6. **Refactor**: Improve code quality while keeping tests green
7. **Repeat**: Continue for each requirement

## Key Principles

- **Red → Green → Refactor**: The core TDD cycle
- **Test behavior, not implementation**: Focus on what the code does, not how
- **One test per requirement**: Keep tests focused and clear
- **Verify test fails first**: Ensures the test is actually testing something

## Examples

When the user says:

- "Write tests for the authentication module"
- "Add tests for the calculateTotal function"
- "I need test coverage for the user registration flow"
- "Test the edge cases for date parsing"

## Notes

- Use TaskCreate to track progress through TDD cycles
- Run full test suite before considering work complete
- Tests should be clear enough to serve as documentation
- Follow existing test patterns in the codebase

Overview

This skill helps you write tests for code using test-driven development (TDD) principles. It guides you through writing failing tests, implementing minimal code to satisfy them, and refactoring while keeping tests green. The focus is behavior-driven, maintainable tests that double as documentation.

How this skill works

You provide the target code, feature description, or requirement and the skill generates focused tests that follow the Red → Green → Refactor cycle. It produces failing test cases first, suggests minimal implementation steps to make them pass, and recommends refactors and follow-up tests. Tests follow existing project patterns and TypeScript testing conventions when applicable.

When to use it

  • Adding coverage for a new feature or endpoint
  • Introducing or documenting expected behavior for a function
  • Validating edge cases and input validation logic
  • Before implementing a complex refactor to avoid regressions
  • When you want tests that serve as executable documentation

Best practices

  • Write one assertion per requirement to keep tests focused
  • Verify the test fails first to ensure it validates behavior
  • Mock external dependencies and test behavior, not implementation
  • Keep test names descriptive and include expected outcome
  • Run the full test suite after changes and before merge

Example use cases

  • Create failing unit tests for an authentication module, then implement minimal login logic to pass them
  • Add tests for calculateTotal covering rounding, discounts, and edge cases, then implement the function iteratively
  • Define end-to-end tests for user registration flow and implement steps until all tests pass
  • Write tests for date parsing edge cases (invalid formats, timezones) and then harden the parser

FAQ

Do you produce full test code or just test cases?

I generate runnable test code following your project's patterns, plus guidance for the minimal implementation needed to pass each test.

Which testing frameworks do you support?

I default to common TypeScript test frameworks and patterns used in the codebase; specify Jest, Mocha, or others if you need a particular style.