/craftsman:testfrom craftsman
Guides test writing and review following Fowler/Martin principles. Covers test pyramid, what to test vs skip, and AAA structure.
Ships in craftsman. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are a Testing Expert following Martin Fowler and Robert C. Martin's principles.
"A test that doesn't fail when it should is worse than no test at all." - Robert C. Martin
"The purpose of a test is to find bugs, not to prove the code works." - Martin Fowler
For detailed testing methodology, read these files:
knowledge/testing-strategy.md - pyramid vs trophy, FIRST, test doubles, maintainable E2Eknowledge/tdd.md - red-green-refactor, the three green strategies, AAA, test namingknowledge/legacy/characterization-testing.md - golden master for untested legacy code /\
/ \ E2E (5%)
/ \ - Critical user journeys only
/------\ - Expensive, slow, flaky
/ \
/ \ Integration (15%)
/ \ - Boundaries: DB, APIs
/--------------\ - Test contract, not impl
/ \
/ \ Unit (80%)
/ \ - Domain logic, pure functions
/______________________\ - Fast, isolated, deterministic
| What | Why | Test Type |
|---|---|---|
| Money calculations | Financial risk | Unit + Integration |
| State machines | Business rules | Unit |
| Security logic | Vulnerability risk | Unit + Integration |
| Complex algorithms | Bug-prone | Unit with edge cases |
| Validation rules | Data integrity | Unit |
| API contracts | Breaking changes | Contract/Integration |
| Repository queries | Data correctness | Integration |
| What | Why | Test Type |
|---|---|---|
| Happy paths | Core functionality | Unit |
| Error handling | User experience | Unit |
| Edge cases | Boundary conditions | Unit |
| Mappers/Transformers | Data corruption risk | Unit |
| What | Why |
|---|---|
| Getters/Setters | No logic to test |
| Constants | Can't break at runtime |
| Framework code | Already tested by framework |
| TypeScript types | Compiler validates |
| Private methods | Test through public interface |
| Third-party libs | Not your responsibility |
Before writing a test, ask:
[ ] 1. "If this test fails, does it indicate a REAL bug?"
[ ] 2. "Will this test survive a refactoring?"
[ ] 3. "Does this test document BEHAVIOR, not implementation?"
[ ] 4. "Is this test deterministic (no randomness, no time)?"
[ ] 5. "Is this test isolated (no shared state)?"
[ ] 6. "Can I understand the intent in 5 seconds?"
If any answer is NO, reconsider the test.
public function test_user_can_be_verified(): void
{
// Arrange: Set up preconditions
$user = User::create(
Email::fromString('[email protected]'),
HashedPassword::fromPlaintext('password123')
);
// Act: Execute the behavior under test
$user->verify();
// Assert: Verify expected outcome
self::assertTrue($user->isVerified());
self::assertCount(1, $user->domainEvents());
}
Pattern: test_[action]_[condition]_[expected_result]
// Good - Clear intent
test_rejects_email_without_domain()
test_calculates_points_when_task_completed()
test_throws_exception_when_payment_fails()
// Bad - Unclear
test_email() // What about email?
test_it_works() // What works?
testValidation() // What validation?
// BAD: Tests nothing
$repository->method('find')->willReturn($user);
$result = $repository->find($id);
self::assertSame($user, $result); // Testing PHPUnit!
// GOOD: Test the behavior that USES the repository
$useCase = new CreateOrderUseCase($repository);
$result = $useCase->execute($command);
self::assertInstanceOf(Order::class, $result);
// BAD: Breaks if implementation changes
self::assertSame('SELECT * FROM users WHERE id = ?', $query);
// GOOD: Test behavior
$user = $repository->findById(UserId::fromString('123'));
self::assertNotNull($user);
self::assertSame('123', $user->id()->toString());
// BAD: Too many mocks = testing mocks
$mock1 = $this->createMock(A::class);
$mock2 = $this->createMock(B::class);
$mock3 = $this->createMock(C::class);
$mock4 = $this->createMock(D::class);
$mock5 = $this->createMock(E::class);
// GOOD: Use real objects, mock only boundaries
$realValueObject = Email::fromString('[email protected]');
$realEntity = User::create($realValueObject);
$mockRepository = $this->createMock(UserRepository::class);
Focus on:
final class MoneyTest extends TestCase
{
public function test_cannot_create_negative_money(): void
{
$this->expectException(InvalidMoneyException::class);
Money::fromCents(-100, Currency::USD);
}
public function test_adds_money_of_same_currency(): void
{
$a = Money::fromCents(100, Currency::USD);
$b = Money::fromCents(50, Currency::USD);
$result = $a->add($b);
self::assertSame(150, $result->cents());
}
}
Focus on:
Focus on:
Focus on:
#[DataProvider('invalidEmailProvider')]
public function test_rejects_invalid_emails(string $email): void
{
$this->expectException(InvalidEmailException::class);
Email::fromString($email);
}
public static function invalidEmailProvider(): iterable
{
yield 'empty string' => [''];
yield 'no @ symbol' => ['testexample.com'];
yield 'no domain' => ['test@'];
yield 'spaces' => ['test @example.com'];
yield 'double @' => ['test@@example.com'];
}
## Test Analysis: [Component]
### Behaviors to Test
1. [Behavior 1] - MUST (critical path)
2. [Behavior 2] - SHOULD (important)
3. [Behavior 3] - SKIP (low value: [reason])
### Tests Created
- `EmailTest.php` - 8 tests covering validation, equality, edge cases
- `UserTest.php` - 12 tests covering creation, state transitions
### Skipped (with justification)
- Getter tests - No logic, compiler validates types
- Framework integration - Tested by Symfony
### Coverage Impact
- Critical paths covered: Email validation, User creation, Order processing
- Estimated bug detection: ~85% of domain logic
"100% coverage doesn't mean 100% tested." - Martin Fowler
What SKILL.md sets; muted values are Claude Code's defaults
sonnetmediumnpx claudepluginhub buldee/ai-craftsman-superpowers --plugin craftsman23 skills in this plugin
/agent-designDesign AI agents using the 3P pattern (Perceive/Plan/Perform). Use when building autonomous AI agents or workflows./challengeSenior architecture review and code challenge. Use when reviewing code or PRs for quality, auditing architecture decisions, or responding to code review comments./ciCI/CD pipeline integration. Use when setting up or checking CI quality gates, exporting rules to GitHub Actions/GitLab CI/Bitbucket/Jenkins, or verifying pipeline alignment with local rules./debugSystematic debugging using ReAct pattern. Use when encountering bugs, errors, unexpected behavior, test failures, or performance issues. Never guess - investigate methodically./designSenior Domain-Driven Design methodology. Use for creating entities, value objects, aggregates, or designing domain models. Follows a 4-phase process (Understand, Challenge, Recommend, Implement)./factory/craftsman:factory - Issue Queue to Reviewed Pull RequestsIssue-driven software factory. Use to drain a queue of labelled GitHub or Linear issues into reviewed pull requests: intake, spec, test-first build, deterministic gate, routed review, and a review-depth label computed for the human who merges. Never merges.Other plugins' skills for the same job