Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP)...

Preview:

Citation preview

Test Driven Development

Daniel Browndxb17u

Introduction

• Originates from Extreme Programming (XP)

• Proposed by Kent Beck in 2003.

• Test Driven Development (TDD) is a feature of XP

• Software Development Technique

• Based on Unit Testing

• Main goal is to produce “clean code that works” (Kent Beck)

What is TDD?

• TDD has only two simple rules:

1. Write code only if a test has failed

2. Eliminate Duplication at each stage

• These two rules imply an order to the tasks of programming.

TDD Cycle

Write a test that fails

Write code to pass the test

Ensure code passes test

Refactor

• Process is commonly described as the red/green/refactor programming mantra

Fail

Pass

Refactoring

• Used to eliminate duplication in TDD.

• “Process of improving the design of code without changing its behaviour”.

• Other goals include:• Improving extensibility

• Improving performance• Changing code to adhere to coding standards

Direct Implications

• Reduces defect density of the code

• Programmers become more focused on system requirements.

• Unit Tests can become part of the system documentation.

• Increases developer understanding of parts of the system.

TDD and XP Values

• TDD development helps to support the main values of XP.

1. Communication

• Particularly relevant to agile development methodologies.

2. Feedback

3. Simplicity

4. Courage

Communication

• More likely to involve customer in development

• Improves Customer-Developer Communication

• Improves Developer-Developer communication

• Collective Code ownership

• Unit tests proved a means to understand code

Feedback

• Regular system releases to customer.

• Developers can respond to customer feedback efficiently.

• Constant unit testing

• Short iterations through TDD cycle

• TDD maximises system feedback and customer feedback.

Simplicity

• Each function is implemented one by one

• Reduces scope creep

• Customer has more control over the system being developed

Courage

• Keeps developers focused on implementing the current requirement

• Eliminates developer “fear”

• Beck states that fear has a number of negative effects.

Drawbacks

• Unit tests which repeatedly failed.

• Large number of tests = maintenance overhead.

• Tests are commonly written by the developer.

• Vast number of tests passing may bring a false sense of security.

Questions?