协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
write-tests【开发与工程】Write unit and integration tests. Use when the user says "write tests for this", "add test coverage", "how do I test this", "TDD", "red green refactor", "unit test this function", "test this module", "I need tests for", or has code that lacks tests - even if they don't explicitly say "write tests".
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Based on "Test Driven Development By Example" by Kent Beck. Beck's core insight: tests are not a tax on development - they are the way you design. Writing the test first forces you to think about the interface before the implementation. Code written test-first tends to be more modular, more focused, and easier to change.
The TDD cycle: Red - Green - Refactor
For a given function or module, list the behaviors to test:
Don't write tests for implementation details - test behavior.
Write a test that:
test_<action>_<condition>_<expected_result>Example in Python:
def test_withdraw_fails_when_balance_insufficient():
# Arrange
account = BankAccount(balance=50)
# Act + Assert
with pytest.raises(InsufficientFundsError):
account.withdraw(100)
Run the test. Confirm it fails for the right reason (not a syntax error).
Write the simplest code that makes the test pass. Do not gold-plate. Do not add features not tested yet. Run the test. Confirm it passes.
Clean up:
Run all tests after each refactor step. Tests are the safety net.
Add one test at a time. After each Red-Green-Refactor cycle, all tests should pass.
Unit tests cover individual functions. Integration tests cover how components connect.
1. Testing implementation instead of behavior Bad: Testing that a specific private method was called. Good: Testing that the observable output is correct given the input.
2. Tests that depend on each other Bad: Test B only works if Test A ran first. Good: Each test is fully independent. Any test can run in any order.
3. Writing tests after the code Bad: Code written first, tests added later to hit coverage targets. Good: Test first. The discipline is the point - it changes how you design.
4. One massive test instead of many small ones Bad: One test that covers 10 behaviors. Good: One behavior per test. When a test fails, you know exactly what broke.
test_action_condition_result