Automated Testing & TDD Cycle
Automate the Red-Green-Refactor development cycle with strict test verification and zero unverified claims.
The Problem
AI models frequently claim tests are passing without actually running the test binary. Unchecked assertions and obsolete test suites create a false sense of security.
Who It Is For
Engineers who prioritize high software quality, high test coverage, and bulletproof regressions.
Prerequisites & Tools
- Configured test runner (Node Test Runner, Jest, Vitest, PHPUnit, Paratest, PyTest)
| Tool / Command | Type | Role in Tutorial |
|---|---|---|
| create_tests | mcp | Draft comprehensive test scenarios before coding |
| run_tests | mcp | Execute test runner and capture stdout/stderr evidence |
| analyze_change | mcp | Analyze change impact and suggest targeted regression tests (mode: tests) |
Example Task Contract
Exact start_task payload representing this workflow in DevWorkflow local-first governance.
{
"description": "Implement coupon code validation service using strict TDD",
"type": "feature",
"plan": [
"Write failing tests for expired, invalid, and minimum-spend coupon codes",
"Implement CouponValidator domain service",
"Run test runner and verify 100% green suite"
],
"definitionOfDone": [
"Failing test verified failing before implementation",
"All coupon validation rules covered by unit tests",
"Test suite passes with 0 failures and >90% coverage"
]
}Step-by-Step Tutorial Workflow
Follow these sequential actions with validated copyable commands and expected outputs.
Draft Test Scenarios (Red Phase)
Create test files first. Run the test command and verify that the tests fail as expected.
node --test tests/calculator.test.js✖ calculateDiscount throws expected error (0.4ms)
AssertionError: expected 15, got undefinedImplement Passing Logic (Green Phase)
Write the minimum code required to turn all tests green.
node --test tests/calculator.test.js✔ calculateDiscount applies tier percentage (1.1ms)
ℹ tests 6 · pass 6 · fail 0Refactor & Verify (Refactor Phase)
Clean up code structure without altering public behavior. Ensure tests remain 100% green.
npm testAll test suites passing.Verification Steps
Verify that your work genuinely satisfies the task contract before closing.