vooster__tdd.mdc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ---
  2. description:
  3. globs:
  4. alwaysApply: true
  5. ---
  6. # TDD Process Guidelines - Cursor Rules
  7. ## ⚠️ MANDATORY: Follow these rules for EVERY implementation and modification
  8. **This document defines the REQUIRED process for all code changes. No exceptions without explicit team approval.**
  9. ## Core Cycle: Red → Green → Refactor
  10. ### 1. RED Phase
  11. - Write a failing test FIRST
  12. - Test the simplest scenario
  13. - Verify test fails for the right reason
  14. - One test at a time
  15. ### 2. GREEN Phase
  16. - Write MINIMAL code to pass
  17. - "Fake it till you make it" is OK
  18. - YAGNI principle
  19. ### 3. REFACTOR Phase
  20. - Remove duplication
  21. - Improve naming
  22. - Simplify structure
  23. - Keep tests passing
  24. ## Test Quality: FIRST Principles
  25. - **Fast**: Milliseconds, not seconds
  26. - **Independent**: No shared state
  27. - **Repeatable**: Same result every time
  28. - **Self-validating**: Pass/fail, no manual checks
  29. - **Timely**: Written just before code
  30. ## Test Structure: AAA Pattern
  31. ```
  32. // Arrange
  33. Set up test data and dependencies
  34. // Act
  35. Execute the function/method
  36. // Assert
  37. Verify expected outcome
  38. ```
  39. ## Implementation Flow
  40. 1. **List scenarios** before coding
  41. 2. **Pick one scenario** → Write test
  42. 3. **Run test** → See it fail (Red)
  43. 4. **Implement** → Make it pass (Green)
  44. 5. **Refactor** → Clean up (Still Green)
  45. 6. **Commit** → Small, frequent commits
  46. 7. **Repeat** → Next scenario
  47. ## Test Pyramid Strategy
  48. - **Unit Tests** (70%): Fast, isolated, numerous
  49. - **Integration Tests** (20%): Module boundaries
  50. - **Acceptance Tests** (10%): User scenarios
  51. ## Outside-In vs Inside-Out
  52. - **Outside-In**: Start with user-facing test → Mock internals → Implement details
  53. - **Inside-Out**: Start with core logic → Build outward → Integrate components
  54. ## Common Anti-patterns to Avoid
  55. - Testing implementation details
  56. - Fragile tests tied to internals
  57. - Missing assertions
  58. - Slow, environment-dependent tests
  59. - Ignored failing tests
  60. ## When Tests Fail
  61. 1. **Identify**: Regression, flaky test, or spec change?
  62. 2. **Isolate**: Narrow down the cause
  63. 3. **Fix**: Code bug or test bug
  64. 4. **Learn**: Add missing test cases
  65. ## Team Practices
  66. - CI/CD integration mandatory
  67. - No merge without tests
  68. - Test code = Production code quality
  69. - Pair programming for complex tests
  70. - Regular test refactoring
  71. ## Pragmatic Exceptions
  72. - UI/Graphics: Manual + snapshot tests
  73. - Performance: Benchmark suites
  74. - Exploratory: Spike then test
  75. - Legacy: Test on change
  76. ## Remember
  77. - Tests are living documentation
  78. - Test behavior, not implementation
  79. - Small steps, fast feedback
  80. - When in doubt, write a test