test-first-patterns
Skill4 starsChanged 8 months agoMITArchived repositoryView on GitHub
Load when writing tests, creating .feature files, setting up conftest, discussing test strategy, or reviewing coverage. Tests are written BEFORE code. Always. No exceptions. The order is: Design Doc → BDD Scenarios → Unit Tests → Implementation. BDD scenarios come from the design document's use cases section — they are a direct translation of business requirements into executable specifications. This makes tests the living documentation of business logic. BDD scenarios live in tests/features/*.feature and describe behaviour from the user's perspective.…
- Reads credentials
In this repository23 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- claude-api-patternsSkill
- critical-analysisSkill
- database-migration-safetySkill
- data-validationSkill
- design-doc-creatorSkill
- experiment-trackingSkill
- fastapi-patternsSkill
- github-actionsSkill
- htmx-frontendSkill
- infra-yandex-cloudSkill
- langgraph-patternsSkill
- ml-data-handlingSkill
- multimodal-routerSkill
- nlp-slm-patternsSkill
- predictive-analyticsSkill
- prompt-engineeringSkill
- python-project-standardsSkill
- rag-vector-dbSkill
- skill-developerSkill
- supply-chain-auditorSkill
- windows-developerSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 21
Use pytest-bdd (not Behave — stays within pytest ecosystem).
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
Test-First Patterns
When to Load This Skill
Load when writing tests, creating .feature files, setting up conftest, discussing test strategy, or reviewing coverage.
Philosophy
Tests are written BEFORE code. Always. No exceptions.
The order is: Design Doc → BDD Scenarios → Unit Tests → Implementation.
BDD scenarios come from the design document's use cases section — they are a direct translation of business requirements into executable specifications. This makes tests the living documentation of business logic.
Two-Layer Testing Strategy
Layer 1: BDD (Behaviour-Driven Development)
BDD scenarios live in tests/features/*.feature and describe behaviour from the user's perspective. They directly correspond to use cases in design-doc.md.
Use pytest-bdd (not Behave — stays within pytest ecosystem).
Feature: User asks a question to the knowledge base assistant
Scenario: Successful answer from knowledge base
Given the knowledge base contains documents about system usage
When the user asks "How do I add a new user?"
Then the assistant returns an answer with steps
And the answer references the relevant document section
Scenario: Question outside knowledge base scope
Given the knowledge base contains documents about system usage
When the user asks "What is the weather in Moscow?"
Then the assistant responds that it cannot answer this question
And no hallucinated information is returnedLayer 2: Unit Tests (TDD Red-Green-Refactor)
Unit tests cover individual functions and classes in core/ and services/. They use pytest directly.
import pytest
from src.project_name.core.domain import KnowledgeQuery, QueryResult
def test_query_result_is_empty_when_no_documents_match():
query = KnowledgeQuery(text="unrelated question", top_k=3)
result = QueryResult(matches=[], query=query)
assert result.is_empty is True
def test_query_result_is_not_empty_when_matches_exist():
query = KnowledgeQuery(text="how to add user", top_k=3)
result = QueryResult(matches=["doc1", "doc2"], query=query)
assert result.is_empty is Falseconftest.py Standard Structure
import pytest
import pytest_asyncio
from httpx import AsyncClient
from src.project_name.main import create_app
@pytest.fixture(scope="session")
def app():
return create_app()
@pytest_asyncio.fixture
async def client(app):
async with AsyncClient(app=app, base_url="http://test") as ac:
yield ac
@pytest.fixture
def mock_settings(monkeypatch):
monkeypatch.setenv("OPENROUTER_API_KEY", "test-key")
monkeypatch.setenv("DATABASE_URL", "sqlite+aiosqlite:///:memory:")pytest-bdd Step Definitions Pattern
from pytest_bdd import given, scenarios, then, when
scenarios("../features/knowledge_base.feature")
@given("the knowledge base contains documents about system usage")
def knowledge_base_with_docs(kb_service):
kb_service.load_fixture_documents()
@when('the user asks "How do I add a new user?"')
def user_asks_question(client, context):
context["response"] = client.post("/api/v1/chat", json={"message": "How do I add a new user?"})
@then("the assistant returns an answer with steps")
def response_contains_steps(context):
assert context["response"].status_code == 200
assert "steps" in context["response"].json()["answer"].lower()Coverage Requirements
- Minimum 80% overall (enforced in
pyproject.toml) - 100% coverage for
core/— domain logic must be fully tested adapters/can be lower — use integration tests with real services when possible
Running Tests
uv run pytest # all tests with coverage
uv run pytest tests/unit/ -v # unit only
uv run pytest tests/features/ -v # BDD only
uv run pytest -k "test_query" -v # filter by name
uv run pytest --cov-report=html # HTML coverage reportTest File Naming Convention
tests/
├── unit/
│ ├── core/
│ │ └── test_domain.py
│ └── services/
│ └── test_item_service.py
├── integration/
│ └── test_api_endpoints.py
└── features/
├── knowledge_base.feature
└── steps/
└── test_knowledge_base_steps.pyDoes 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.

