Test Driven Development Flashcards

1
Q

Test Driven Development:

Basic Idea

A
  • Think about what code should do before writing any code
  • Write a test for that requirement
  • Write the simplest possible code that passes that test, without causing it to fail existing tests
  • Refactor code as necessary to pass all tests

The idea is to meet requirements incrementally and always have working code.

This is called the “Red-Green-Refactor” cycle

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

Benefits of

Test Driven Development

A
  • Confidence in Change:
    • Increase overall confidence in the code
    • Fearlessly change code
  • Provides Documentation of Requirements
  • Discover Usability issues early
  • Results in high quality software
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Test Driven Development:

Three Laws

A

DO NOT write production code until you have written failing unit tests

DO NOT write more of a unit than is sufficient to fail

DO NOT write more production code than is sufficient to pass the currently failing test

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

Test Driven Development:

Most Important Rule

A

DO NOT

Write code in your head

BEFORE

You write the TEST

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

Test Driven Development

Cycle

A

Write Test Code (Red)

Write Functional Code (Green)

Refactor

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

TDD Cycle:

Write Test Code (Red) Phase

Purpose and Benefits

A
  • Write a test that fails
  • Guarantees all code is testable
  • Provides specification for the code that will be written in the next phase
  • Helps you think about the design
  • Ensures functional code is tangible
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TDD Cycle:

Write Functional Code (Green) Phase

Purpose and Benefits

A
  • Write the simplest working solution
  • Fulfill the requirements of the test code
  • Leave improvements/optimizations for later
  • Code written is only designed to pass the test
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

TDD Cycle:

Refactor Phase

Purpose and Benefits

A
  • Clean up all code (test and production)
  • Make sure code expresses intent
  • Rethink/optimize design
  • Delete unnecessary code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly