30
© 2013 iZenBridge | CONFIDENTIAL Introduction to Test Driven Development (TDD)

Workshop on Test Driven Development (TDD) Noida

Embed Size (px)

Citation preview

© 2013 iZenBridge | CONFIDENTIAL

Introduction

to

Test Driven

Development

(TDD)

© 2013 iZenBridge | CONFIDENTIAL

Introductions!

1.Your Name

2.Current company & Role

3.Experience with Agile and TDD

© 2013 iZenBridge | CONFIDENTIAL

Agile Software Development

© 2013 iZenBridge | CONFIDENTIAL

Traditional Design – Code – Test

Design Code Test

Test Code Design /

Refactor

© 2013 iZenBridge | CONFIDENTIAL

Why Not Testing at the End?

• Hard to improve quality of

existing code – Complacency and Recency

• Feedback opportunity is

lost

• The future state of the

project is difficult to gauge

• Testing is more likely to be

cut

© 2013 iZenBridge | CONFIDENTIAL

Stress and Testing

Project

Stress

Less

Testing

Just get it done, will ya?

© 2013 iZenBridge | CONFIDENTIAL

Test Automation Pyramid

UI

Service

Unit

UI

Service

Unit

Agile Traditional

© 2013 iZenBridge | CONFIDENTIAL

Test First Development

ATDD and TDD

© 2013 iZenBridge | CONFIDENTIAL

ATDD vs TDD

Source: Test Driven: Practical TDD and Acceptance TDD for Java Developers

© 2013 iZenBridge | CONFIDENTIAL

Why TDD?

The Benefits of TDD:

• Limits WIP – a key Lean principle

• Ensures testing at lower granularity level – the smallest

testable unit of code

• Ensures no untested code goes to production

• Helps high degree of conformity between code and the

real business requirements

• Helps keep unused code out of the system (unwritten)

• Makes codebase more maintainable – via regression

testing

© 2013 iZenBridge | CONFIDENTIAL

The TDD Cycle

Red

Green

Clean

Test

Code

Refactor

© 2013 iZenBridge | CONFIDENTIAL

Three Laws/ Rules of TDD

You will not write any production

code until you have written a failing

unit test.

First Law

© 2013 iZenBridge | CONFIDENTIAL

Three laws of TDD

You will not write more of a unit

test than is sufficient to fail, and

not compiling is failing

Second Law

© 2013 iZenBridge | CONFIDENTIAL

Three laws of TDD

You will not write more production

code that is sufficient to pass the

currently failing test.

Third Law

© 2013 iZenBridge | CONFIDENTIAL

Misconceptions About TDD

• Writing code first, then tests is

same as TDD

• TDD isn’t useful for designing

architecture

• Takes too much time

• Too complex to learn and

implement

• TDD is only good for small

projects

© 2013 iZenBridge | CONFIDENTIAL

© 2013 iZenBridge | CONFIDENTIAL

Let’s Build Something Now!

© 2013 iZenBridge | CONFIDENTIAL

String Calculator – TDD Exercise

Define Scope:

• Supported operators?

• Acceptable characters?

• Whitespace?

• Max length of expression – number of operations?

• Max length of each number?

• Fractions?

• Parenthesis?

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

Time to start Failing!

• Reminders: • Test, Code, Refactor – REPEAT until Done!

• Add feature layers one by one, in small manageable increments

• Setup • Eclipse for Java Development

• JDK

• Team formation

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

1. Two literal addition

A + B

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

2. Multiple literal addition

A + B + C

A + B + C + D

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

3. Combination of addition and subtraction

A + B – C

or

A – B + C

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

4. Simple multiplication

A * B

A * B * C

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

5. Simple division

A / B

A / B / C

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

6. Combination of multiplication

and division

A * B / C

A / B * C

Does order matter?

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

7. Combination of all four

A + B – C * D / E

Order does matter here!

© 2013 iZenBridge | CONFIDENTIAL

String Calculator (continued)

8. Invalid expressions

• Banned chars - alpha, parenthesis, special chars

• Space between a number

• Two operators clubbed together

• First number negative

• Invalid decimal number

© 2013 iZenBridge | CONFIDENTIAL

What Next?

Certified Scrum Developer (CSD)

A 3-day course certified by Scrum Alliance that focuses on

specialized Agile engineering skills:

Test Driven Development (TDD)

ATDD, BDD – Selenium/ Cucumber

Continuous Integration – Jenkins

Agile Design and Architecture

Refactoring

Collaboration

© 2013 iZenBridge | CONFIDENTIAL

References

Test Driven Development: By Example - Kent Beck

Succeeding with Agile - Mike Cohn

Test Driven: Practical TDD and Acceptance TDD for Java

Developers - Lasse Koskela

© 2013 iZenBridge | CONFIDENTIAL

Stay Connected

YouTube

www.youtube.com/izenbridge

LinkedIn Group

PMI-ACP: Agile Certification Made Easy

[email protected]

[email protected]

www.iZenBridge.com

forum.iZenBridge.com