13
Test Driven Development Daniel Brown dxb17u

Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

Embed Size (px)

Citation preview

Page 1: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

Test Driven Development

Daniel Browndxb17u

Page 2: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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)

Page 3: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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.

Page 4: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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

Page 5: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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

Page 6: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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.

Page 7: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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

Page 8: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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

Page 9: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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.

Page 10: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

Simplicity

• Each function is implemented one by one

• Reduces scope creep

• Customer has more control over the system being developed

Page 11: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

Courage

• Keeps developers focused on implementing the current requirement

• Eliminates developer “fear”

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

Page 12: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

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.

Page 13: Test Driven Development Daniel Brown dxb17u. Introduction Originates from Extreme Programming (XP) Proposed by Kent Beck in 2003. Test Driven Development

Questions?