© alexandre cuva version 2.00 test driven design

27
© ALEXANDRE CUVA VERSION 2.00 Test Driven Design

Upload: julie-stafford

Post on 31-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

© A L E X A N D R E C U VA V E R S I O N 2 . 0 0

Test Driven Design

Page 2: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design
Page 3: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design
Page 4: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Alexandre Cuva

• Agile Transition Coach, Scrum Master, Product Owner

• Management 3.0 & Certified Scrum Developer Trainer

• Event speaker

• Hermes Swiss Project Team Professional

• ITIL V3

“I coach teams and organization to become highly productive.”

http://www.slideshare.net/GToronto

Agile Transition Coach

Page 5: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Why should developers write tests?- 5 -

Common responses: “leave testing to QA” “developers are too busy” “developers don’t know how to test” “We don’t have bugs” “developers are intimately familiar with the structure

of the code and are not well-suited for testing it”

Page 6: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

But- 6 -

“if developers don’t test. How do they know that they are producing quality software?”

Tests are a tool to help developers take responsibility for quality

Tests help making small steps and give immediate feedback

Test help maintain focus on measurable outcome of coding – producing the code that accomplishes a concrete objective

Page 7: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Kent Beck say Good unit tests …- 7 -

Express intent, not implementation detailsRun fast (they have short setups, run times,

and break downs)Run in isolation (reordering possible)Run in parallelUse data that makes them easy to read and

to understand

Page 8: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Testing- 8 -

Design

Implement

Test

Page 9: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

TDD- 9 -

Design

Test

Implement

Test

Page 10: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

TDD- 10 -

Design

Test

Implement

Test

Page 11: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

How to do it- 11 -

Design: figure out what you want to doTest: write a test to express the design

It should FAILImplement: write the codeTest: run the test

It should PASS

Page 12: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Test Unit Framework- 12 -

Microsoft Test MSTest Included inside - VS2010 Professional- VS2008 Team System

NUnit Most Used Open SourceMore upToDate than MSTest

xUnit Fork from NUnitMost Used Open Source ?

Page 13: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Visual Studio- 13 -

Have always a separate project for your test. Unit Test : xxxTest ATDD : xxxAcceptanceTest BDD : xxxSpec Integration : xxxIntegrationTest

Page 14: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Visual Studio- 14 -

On Visual Studio : Create a Project “Test Project” Add new Test Select “Basic Unit Test”

Page 15: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Test- 15 -

int expected = 4; // Header

int result = Calculator.Add(2, 2); //Body

Assert.AreEqual(expected, result); //Footer

Page 16: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

FAIL- 16 -

Page 17: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Implement- 17 -

public static int Add(int number1, int number2) { return number1 + number2; }

Page 18: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Test- 18 -

Page 19: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Iterate- 19 -

Design

Test

ImplementTest

Refactor

Page 20: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Try It !- 20 -

Page 21: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Write once, run often- 21 -

Write tests onceKeep them somewhere sensibleRun frequently (one click)No human inputMachine-parsable output

Page 22: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

When should I use TDD- 22 -

AlwaysWrite tests for anything you feel that might

breakDesign of production code should always be

test-drivenNo need to write tests for APIs you don’t own

Page 23: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Two fundamental TDD rules (Kent Beck)- 23 -

Never write a single line of code unless you have a failing automated test.

Eliminate duplication

Page 24: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Refactoring improves design- 24 -

“Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure”

Martin Fowler

Page 25: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

Question ?

25

Page 26: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

- 26 -

Books

Page 27: © ALEXANDRE CUVA  VERSION 2.00 Test Driven Design

27

https://plus.google.com/u/0/102628787365618084989

http://ch.linkedin.com/in/cuvaalex

@cuvaalex (twitter)

http://agile-alexcuva.blogspot.ch (blog)

http://www.slideshare.net/GToronto

management30.com (book)