Date post: | 31-Dec-2015 |
Category: |
Documents |
Upload: | julie-stafford |
View: | 216 times |
Download: | 0 times |
© 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
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
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”
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
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
Testing- 8 -
Design
Implement
Test
TDD- 9 -
Design
Test
Implement
Test
TDD- 10 -
Design
Test
Implement
Test
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
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 ?
Visual Studio- 13 -
Have always a separate project for your test. Unit Test : xxxTest ATDD : xxxAcceptanceTest BDD : xxxSpec Integration : xxxIntegrationTest
Visual Studio- 14 -
On Visual Studio : Create a Project “Test Project” Add new Test Select “Basic Unit Test”
Test- 15 -
int expected = 4; // Header
int result = Calculator.Add(2, 2); //Body
Assert.AreEqual(expected, result); //Footer
FAIL- 16 -
Implement- 17 -
public static int Add(int number1, int number2) { return number1 + number2; }
Test- 18 -
Iterate- 19 -
Design
Test
ImplementTest
Refactor
Try It !- 20 -
Write once, run often- 21 -
Write tests onceKeep them somewhere sensibleRun frequently (one click)No human inputMachine-parsable output
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
…
Two fundamental TDD rules (Kent Beck)- 23 -
Never write a single line of code unless you have a failing automated test.
Eliminate duplication
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
Question ?
25
- 26 -
Books
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)