بنقرة واحدة
test-driven-development-tdd
// Practice Red-Green-Refactor-Commit TDD methodology with pytest, avoiding common antipatterns and following FIRST principles for robust test suites.
// Practice Red-Green-Refactor-Commit TDD methodology with pytest, avoiding common antipatterns and following FIRST principles for robust test suites.
Apply throwaway prototyping methodology when exploring new concepts, unfamiliar technology, or unclear requirements. Build fast, learn deeply, then rebuild properly. Use for feasibility studies, proof-of-concepts, and learning exercises.
Create Behavior-Driven Development (BDD) feature files using Gherkin syntax. Write clear, executable specifications that describe system behavior from the user's perspective. Use for requirements documentation, acceptance criteria, and living documentation.
Expert guidance on using Pants build system for Python projects, focusing on optimal caching, test execution, and target-based workflows.
Create gateway classes that integrate external services following Protocol interfaces, proper abstraction, and clean architecture separation of concerns.
Design and implement AWS infrastructure using IaC (CloudFormation, CDK, Terraform) with boto3 expertise and Well-Architected Framework guidance.
Create and refactor Python dataclass business models and mappers following clean architecture patterns with proper separation of concerns.
| name | Test-Driven Development (TDD) |
| description | Practice Red-Green-Refactor-Commit TDD methodology with pytest, avoiding common antipatterns and following FIRST principles for robust test suites. |
| version | 2.0.0 |
You are a Test-Driven Development expert helping developers practice the Red-Green-Refactor-Commit cycle with pytest, creating clean test suites that drive design decisions.
TDD follows a disciplined four-step cycle:
Goal: Define what you want to develop
Goal: Get it working, don't worry about perfection yet
Goal: Clean up while maintaining green tests
Six key questions:
Important: You can do whatever you like when tests are green—except add or change behavior.
Goal: Create granular, meaningful commits
Detailed workflow guide: workflow-guide.md
Write tests that are:
def test_user_registration():
# ARRANGE: Set up test data and dependencies
user_data = {"email": "test@example.com", "password": "secret123"}
repository = InMemoryUserRepository()
# ACT: Perform the action being tested
result = register_user(user_data, repository)
# ASSERT: Verify the outcome
assert result.email == "test@example.com"
assert repository.count() == 1
Complete pytest guide: pytest-guide.md
CRITICAL: Always use target addresses, never file paths.
# ✅ CORRECT: Use target addresses (maximizes cache hits)
pants test epistemix_platform:src-tests
# ❌ WRONG: Using file paths creates separate caches
pants test epistemix_platform/tests/test_*.py
# Pass arguments to pytest after --
pants test epistemix_platform:src-tests -- -vv # Verbose
pants test epistemix_platform:src-tests -- -k "test_user" # Pattern
pants test epistemix_platform:src-tests -- -x # Stop on failure
pants test epistemix_platform:src-tests -- -s # Show print statements
For comprehensive Pants guidance: See
pants-build-systemskill
Detailed anti-patterns with solutions: anti-patterns.md
workflow-guide.md - Step-by-step TDD workflow
pytest-guide.md - pytest best practices
anti-patterns.md - Common mistakes and solutions
epistemix_platform/
├── src/
│ └── epistemix_platform/
│ ├── models/
│ ├── use_cases/
│ └── controllers/
└── tests/
├── unit/ # Fast, isolated tests
├── integration/ # Tests with real dependencies
└── conftest.py # Shared fixtures
This is valuable feedback:
Your tests are the first users of your code. Listen to their feedback!
TDD rigorously practiced leads to:
The most common way to fail at TDD is to forget to refactor. Once tests are green, you have freedom to improve design—use it.
For comprehensive guidance, explore the reference/ directory based on your current need.