Skip to content
Back to skills

Swe Test First

ASecurity

Part of the Software Engineer pack. The red-green-refactor loop for writing production code - write a failing test, watch it fail for the right reason, write the minimal code to pass, then clean up - testing real behaviour rather than mocks, and what to do when test-first doesn't fit. Use when implementing a feature, bug fix or behaviour change in code that has or can have automated tests. Loaded by the software-engineer agent. Other agents use it only when the user names this skill.

  • 12 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsgotestingdebuggingapidatabase

Works with

  • api

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add MhdAljuboori/ZumiBot --skill swe-test-first --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Swe Test First?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Swe Test First
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mhdaljuboori-swe-test-first/badge)](https://www.skillsdirectory.com/skills/mhdaljuboori-swe-test-first)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: swe-test-first
description: Part of the Software Engineer pack. The red-green-refactor loop for writing production code - write a failing test, watch it fail for the right reason, write the minimal code to pass, then clean up - testing real behaviour rather than mocks, and what to do when test-first doesn't fit. Use when implementing a feature, bug fix or behaviour change in code that has or can have automated tests. Loaded by the software-engineer agent. Other agents use it only when the user names this skill.
---

# Test-first development

Goal: every behaviour you add or change is pinned by a test that you saw fail without your code and pass with it.

## The loop
For each small behaviour (one task of the plan, or one case of it):

1. **Red: write one failing test.**
   - Put it where the project keeps tests, in the project's style and framework. Copy the nearest existing test's setup.
   - Name it after the behaviour: `returns 404 when the order belongs to another user`, not `test_order_2`.
   - Assert on observable results: return values, stored data, HTTP responses, rendered output, emitted events.
2. **Watch it fail, and read why.** Run just that test. It must fail because the behaviour is missing: an assertion failure showing the wrong value, or a clear "not implemented". If it fails on a typo, a missing import, a broken fixture or a syntax error, fix the test and run again. If it passes already, either the behaviour exists (check) or the test does not test what you think. A test you never saw fail proves nothing.
3. **Green: write the minimal code** that makes it pass. No extra options, no handling of cases you have no test for yet. Run the test; then run the neighbouring tests to make sure nothing else broke.
4. **Refactor** with the tests green: remove duplication, improve names, simplify. Run the tests after each change. Refactor only the code you just touched, plus what it needs.
5. Next behaviour. Edge and error cases each get their own red-green round.

## Bug fixes
The first test reproduces the bug: it fails today for the exact reason you found while debugging. Then fix. The test stays as the regression guard.

## Test real behaviour, not mocks
- Mock only what is slow, non-deterministic or outside your control: network, the clock, randomness, third-party services, the file system when it matters. Prefer the project's existing fakes and test helpers.
- Never assert that a mock returned what you told it to return. That tests the mock.
- Don't assert on internal calls ("method X was called twice") when you can assert on the result. Interaction tests break on every refactor and miss real bugs.
- Use real collaborators from your own code where it's cheap: a real parser, a real in-memory store, a real test database if the project has one.
- Don't add test-only methods or flags to production code to make testing easier; improve the seam instead (pass the dependency in).
- Keep tests deterministic: inject the clock and random seeds, no sleeps, no order dependence.

## When test-first doesn't fit
Some work can't sensibly start with an automated test: a pure visual tweak, a build or config change, a throwaway spike, glue code over an untestable third-party API, a repo with no test setup at all.
- Say so explicitly, and say how it will be verified instead: the command, the manual steps, the screenshot, the log line.
- For a spike, throw the spike away and rebuild test-first once you know the shape.
- If the repo has no tests, don't add a whole test framework unasked. Propose it, and verify by other means meanwhile.
- Never silently skip tests and present the work as tested.

## Red flags
- Writing the code first "and the test right after": you lose the proof that the test can fail. If it happened, temporarily revert the code or break the condition and watch the test fail.
- A test changed to match new output without understanding why the output changed.
- Many behaviours added in one step, with one big test at the end.
- `skip`, `only`, commented-out tests or lowered coverage thresholds left behind.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.