click to reveal definition
click to flip back
You know 0 of 22 cards in current set.
Ready to get certified?
Get CertifiedNeed this expertise applied inside your organization?
Explore Our ServicesFull Glossary
Foundations
- Test-Driven Development (TDD)
- A practice of writing an automated test before the code that makes it pass, using tests to drive design and quality.
- Test-First
- Writing the test before the implementation, which clarifies intended behavior and design.
- Why TDD
- TDD yields well-tested, well-designed code, fast feedback, and confidence to change code safely.
- Quality Built In
- TDD builds quality into the code as it is written rather than testing it in afterward.
The Cycle
- Red-Green-Refactor
- Write a failing test (red), make it pass simply (green), then improve the design (refactor).
- Red
- Writing a small failing test that specifies the next desired behavior.
- Green
- Writing the simplest code that makes the test pass.
- Refactor
- Improving code structure without changing behavior, with tests ensuring safety.
- Small Steps
- Working in tiny increments for immediate feedback and easy error detection.
Unit Testing
- Unit Test
- An automated test verifying a small unit of code in isolation.
- Arrange-Act-Assert
- A test structure: set up context, perform the action, then assert the expected result.
- Assertion
- A check that verifies the code produced the expected outcome.
- Test Framework
- A tool (e.g., JUnit, NUnit, pytest) that runs tests and reports results.
- Test Isolation
- Keeping tests independent so they run in any order and pinpoint failures.
Design
- Emergent Design
- Letting design evolve through refactoring as tests drive out behavior.
- Refactoring
- Restructuring code to improve it without changing behavior, made safe by tests.
- Testable Code
- Code with clear responsibilities and manageable dependencies, which is easier to test.
Benefits
- Fast Feedback
- Running tests frequently to catch problems immediately.
- Regression Safety
- A growing test suite that guards against breaking existing behavior.
- Living Specification
- Tests document intended behavior and stay in sync with the code.
Applying It
- Common Pitfalls
- Writing tests after code, testing too much at once, or skipping refactoring undermine TDD.
- Getting Started
- Begin with small units, follow the cycle strictly, and build the habit through practice.