Test-Driven Development (TDD) Flashcards

1
Q

What does TDD stand for, and what is its main purpose?

A

TDD stands for Test-Driven Development.
It emphasizes writing tests before actual code to ensure the code meets requirements and remains maintainable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List four reasons to use TDD.

A

Reliability: Ensures code correctness through automated tests.
Maintainability: Acts as documentation for easier understanding and maintenance.
Refactoring Confidence: Enables safe refactoring with a robust test suite.
Early Bug Detection: Catches bugs early, reducing costs of fixes later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name the three phases of the TDD cycle.

A

Red Phase
Green Phase
Refactor Phase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens during the Red Phase?

A

Write a failing test representing a specific requirement.
Clearly define what needs to be implemented.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens during the Green Phase?

A

Write the minimum code required to make the test pass.
Focus on functionality, not optimization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens during the Refactor Phase?

A

Improve the code without altering its behavior.
Enhance readability, maintainability, and performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the first four best practices for TDD?

A

Start Small: Begin with small, focused tests for clarity and manageability.
Write Failing Tests First: Ensure tests fail initially to validate their effectiveness.
Implement Minimum Code: Write only the code needed to pass the test.
Run Tests Frequently: Catch issues early by regularly running tests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the next four best practices for TDD?

A

Keep Tests Independent: Isolate tests to simplify debugging.
6. Maintain a Fast Test Suite: Optimize test speed for frequent testing.
7. Write Descriptive Tests: Use clear names and assertions for documentation.
8. Test Edge Cases: Cover diverse inputs, including edge cases, for robust coverage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are two common challenges in TDD?

A

Writing Tests for Legacy Code: Start by testing new features or refactoring.
Balancing TDD with Deadlines: Though initially time-consuming, TDD speeds up development over time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly