behavioral-testing
Skill9 starsChanged 4 months agoMITView on GitHub
Behavioral testing methodology — test what users experience, not how code is structured. Use when writing tests, reviewing test quality, planning test strategy for new features, or when existing tests are brittle/verbose/coupled to implementation details. Triggers: writing tests, TDD, test review, "tests keep breaking", "too many mocks", "tests are verbose", test coverage planning, behavior-driven development.
In this repository25 other files it gives its agents.
- adversarial-reviewSkill
- agent-first-repoSkill
- agents-mdSkill
- architecture-mdSkill
- cleanup-swiftSkill
- cleanup-webSkill
- clear-communicationSkill
- code-commentsSkill
- design-patterns-gofSkill
- design-systemSkill
- distill-to-skillSkill
- git-safe-pr-workflowSkill
- git-worktreeSkill
- karpathy-guidelinesSkill
- lean-ts-patternsSkill
- macos-swift-desktopSkill
- modern-cssSkill
- no-use-effectSkill
- parse-dont-validateSkill
- pr-review-triageSkill
- simplifySkill
- technical-writingSkill
- typescript-refactoringSkill
- typescriptSkill
- update-readmeSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Test observable behavior. Keep tests terse.
- Distinctive: line 39
Test behavior at boundaries, not every line of code:
- Distinctive: line 93
Before writing or reviewing any test, run these checks:
- Distinctive: line 118
If you need to mock a thing to test it, the design has a coupling problem — fix the design, not the test.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Behavioral Testing
Test observable behavior. Keep tests terse. Never test implementation details.
Core Laws
1. Test what the user sees, not how the code works
2. If a refactor breaks a test, the test was wrong
3. Mocks isolate — they are never the thing being tested
4. Every assertion must trace to a user-observable outcome
5. Terse tests > thorough ceremonyWriting Tests
The Pattern
Arrange: Set up the minimum preconditions
Act: Do the thing the user would do
Assert: Check what the user would seeThat's it. No red-green-red ritual. No verbose setup. If test setup is longer than the assertion, something is wrong.
What to Test
Test behavior at boundaries, not every line of code:
| Always test | Skip |
| What happens with empty/null/whitespace input | Internal method call order |
| Error messages users see | Which helper function was called |
| State transitions (loading → success → error) | Implementation details of state management |
| API failure recovery | Mock call counts (unless it IS the behavior) |
| Edge cases users will hit | Happy-path-only coverage |
Test Naming
Name tests after the behavior, not the function:
✅ "shows error when email is empty"
✅ "redirects to login after session expires"
✅ "prevents duplicate submission on double-click"
❌ "test validateEmail"
❌ "test handleSubmit calls api"
❌ "test useAuth hook returns null"Keep Tests Terse
// ✅ Terse — tests one behavior, reads in 3 seconds
test('shows error when email is empty', () => {
render(<LoginForm />);
click(submitButton());
expect(screen.getByText('Email is required')).toBeVisible();
});
// ❌ Verbose — ceremony obscures intent
test('should display an error message when the user submits the form without entering an email address', () => {
const mockOnSubmit = vi.fn();
const mockOnError = vi.fn();
const { container } = render(
<LoginForm onSubmit={mockOnSubmit} onError={mockOnError} />
);
const form = container.querySelector('form');
const button = screen.getByRole('button', { name: /submit/i });
await userEvent.click(button);
expect(mockOnSubmit).not.toHaveBeenCalled();
expect(mockOnError).toHaveBeenCalledWith(expect.objectContaining({ field: 'email' }));
expect(screen.getByText('Email is required')).toBeVisible();
});The terse test catches the same bug. The verbose test also asserts on mock internals — those assertions break when you refactor, even if behavior is unchanged.
Stop Checks
Before writing or reviewing any test, run these checks:
□ Am I asserting on a mock instead of real output?
→ If yes: delete the assertion or unmock it
□ Would a refactor break this test even though behavior hasn't changed?
→ If yes: the test is coupled to implementation — rewrite it
□ Is mock setup > 50% of the test?
→ If yes: use an integration test with real components instead
□ Does this test name describe a user-visible behavior?
→ If no: rename it or question whether it needs to exist
□ Did I write this test after the implementation?
→ If yes: verify it actually fails when behavior is broken, not just when code changesWhen to Mock
Mock external boundaries only. Network calls, third-party services, timers — things outside your control.
Never mock internal modules, components you own, or "just to be safe."
If you need to mock a thing to test it, the design has a coupling problem — fix the design, not the test.
Detailed References
Load these only when needed:
- references/anti-patterns.md — Common testing mistakes with examples: testing mock behavior, test-only production methods, incomplete mocks, over-mocking
- references/test-templates.md — Copy-paste test patterns for unit, integration, and E2E tests. Factories, helpers, and terse assertion patterns
- references/branch-coverage.md — Branch matrix methodology for systematic coverage: how to map conditions, prioritize, and verify completeness without testing every permutation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

