Download - #2 Backend Meetup - Introduction to TDD/BDD
![Page 1: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/1.jpg)
INTRODUCTION TOTEST DRIVEN DEVELOPMENT
tw: @MaciejGrajcarek
![Page 2: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/2.jpg)
Check List
1. History of TDD2. TDD Cycles3. BDD4. TDD is dead?5. PHPSpec
![Page 3: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/3.jpg)
Who needs tests anyway?
![Page 4: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/4.jpg)
Who needs tests anyway? Bugs killers!
![Page 5: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/5.jpg)
Technical Debt
![Page 6: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/6.jpg)
Technical Debt
![Page 7: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/7.jpg)
Where it all beganWaterfall Model
Winston W. Royce (1970)
![Page 8: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/8.jpg)
Where it all beganAgile – best friend of TDD
- Adaptive vs Predictive- Iterative vs Waterfall
2001 – Agile Manifesto
![Page 9: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/9.jpg)
Where it all beganScrum Cicle
Analysis
Programming
Testing
Acceptance
![Page 10: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/10.jpg)
Where it all began
„Test Driven Development: By Example” – Kent Beck (2003)
![Page 11: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/11.jpg)
Check List
1. History of TDD2. TDD Cycle of life3. BDD4. TDD is dead?5. PHPSpec
![Page 12: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/12.jpg)
TDD Cycle of life
Failing Test
Pass testRefactoring
![Page 13: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/13.jpg)
TDD Cycle of life
Failing Test
•Make test compile•Make sure it doesn’t pass
![Page 14: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/14.jpg)
First simple failing test
function checkSumTest()
{
$a = 5;
$b = 4;
$calculator = new Calculator();
$sum = $calculator->sum($a, $b);
$this->assertEqual(9, $sum);
}
![Page 15: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/15.jpg)
TDD Cycle of life
Pass test
•Fake It (Till You Make It)•Type The Obvious Implementation•Triangulation
![Page 16: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/16.jpg)
Fake It (Till You Make It)
class Calculator
{
function sum($a, $b)
{
return 9;
}
}
![Page 17: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/17.jpg)
Type The Obvious Implementation
class Calculator
{
function sum($a, $b)
{
$sum = $a + $b;
return $sum;
}
}
![Page 18: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/18.jpg)
Triangulation
At least two points needed to find a location.
![Page 19: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/19.jpg)
Triangulation
//Test 1$sum = $calculator->sum($a, $b);$this->assertEqual(9, $sum);
class Calculator{function sum($a, $b)
{ $sum = $a + $b; return $sum;}
}
![Page 20: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/20.jpg)
Triangulation
//Test 1$sum = $calculator->sum(4, 5);$this->assertEqual(9, $sum);
//Test 2$sum = $calculator->sum(4, 5, 7);$this->assertEqual(16, $sum);
class Calculator{
function sum($a, $b, $c = 0) {
$sum = $a + $b + $c; return $sum;}
}
![Page 21: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/21.jpg)
Triangulation
//Test 1$sum = $calculator->sum(4, 5);$this->assertEqual(9, $sum);
//Test 2$sum = $calculator->sum(4, 5, 7);$this->assertEqual(16, $sum);
//Test 3$sum = $calculator->sum(4, 5, 7, 1);$this->assertEqual(17, $sum);
![Page 22: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/22.jpg)
Triangulation
class Calculator{function sum()
{$elements = func_get_args();$sum = 0;foreach ($elements as $el) {
$sum += $el;}return $sum;
}}
![Page 23: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/23.jpg)
Triangulation
//Test 1$sum = $calculator->sum(4, 5);$this->assertEqual(9, $sum);
//Test 2$sum = $calculator->sum(4, 5, 7);$this->assertEqual(16, $sum);
//Test 3$sum = $calculator->sum(4, 5, 7, 1);$this->assertEqual(17, $sum);
![Page 24: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/24.jpg)
Triangulation
//Final test$sum = $calculator->sum(4, 5, 7, 1);
$this->assertEqual(17, $sum);
![Page 25: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/25.jpg)
TDD Cycle of life
Refactoring•KISS•DRY
![Page 26: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/26.jpg)
Maintainability, Flexibility, Portability, Reusability, Readability, Scalability, Testability, Understandability
![Page 27: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/27.jpg)
Don’t Repeat Yourself
1) Extract Shared Concept
2) Give it a name
3) Reuse it
If impossible to do 1-2, there is no repetition
![Page 28: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/28.jpg)
TDD Cycle of life
Failing Test
Pass testRefactoring
![Page 29: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/29.jpg)
Check List
1. History of TDD2. TDD Cycle of life
1. Red phase2. Green phase3. Refactoring
3. Tests measurement4. TDD Tips5. BDD6. TDD is dead?7. PHPSpec
![Page 30: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/30.jpg)
Tests measurement
1. Code Coverage2. Underlay Defects
- 100 % code coverage != Error Free- Vendor code should have 100% code
coverage, but yours not necessarily
![Page 31: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/31.jpg)
TDD Tips
1. Create a check list of tests
![Page 32: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/32.jpg)
TDD Tips
1. Create a check list of tests2. Small step approach during
refactorization (or larger when fealing comfortable)
![Page 33: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/33.jpg)
TDD Tips
1. Create a check list of tests2. Small step approach during
refactorization (or larger when fealing comfortable)
3. Add problems to the list, instead of resolving them immediately
![Page 34: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/34.jpg)
TDD Tips
1. Create a check list of tests2. Small step approach during
refactorization (or larger when fealing comfortable)
3. Add problems to the list, instead of resolving them immediately
4. Never create new test if previous one is failing
![Page 35: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/35.jpg)
TDD Tips
1. Create a check list of tests2. Small step approach during
refactorization (or larger when fealing comfortable)
3. Add problems to the list, instead of resolving them immediately
4. Never create new test if previous one is failing
5. Remove repetition (between code and test too!)
![Page 36: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/36.jpg)
TDD Tips
1. Create a check list of tests2. Small step approach during refactorization
(or larger when fealing comfortable)3. Add problems to the list, instead of
resolving them immediately4. Never create new test if previous one is
failing5. Remove repetition (between code and test
too!)6. Tests should be fast and isolated
![Page 37: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/37.jpg)
TDD Tips
1. Create a check list of tests2. Small step approach during refactorization (or
larger when fealing comfortable)3. Add problems to the list, instead of resolving
them immediately4. Never create new test if previous one is failing5. Remove repetition (between code and test
too!)6. Tests should be fast and isolated7. Test only public
![Page 38: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/38.jpg)
TDD Tips
1. Create a check list of tests2. Small step approach during refactorization (or
larger when fealing comfortable)3. Add problems to the list, instead of resolving
them immediately4. Never create new test if previous one is failing5. Remove repetition (between code and test too!)6. Tests should be fast and isolated7. Test only public8. Write your own tests, don’t wait for a
teammate
![Page 39: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/39.jpg)
London vs Brooklyn School of TDD
Is it all about Mocks?
![Page 40: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/40.jpg)
Check List
1. History of TDD2. TDD Cycle of life
1. Red phase2. Green phase3. Refactoring
3. Tests measurement4. TDD Tips5. London vs Brooklyn6. BDD7. TDD is dead?8. PHPSpec
![Page 41: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/41.jpg)
Behavior Driven Development- Based on TDD- Test behavior, not code!- Domain Driven Desing- DSL in test tools- „it_should”- Gherkin [Given, When, Then]- Tests as specification
![Page 42: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/42.jpg)
Check List
1. History of TDD2. TDD Cycle of life
1. Red phase2. Green phase3. Refactoring
3. Tests measurement4. TDD Tips5. London vs Brooklyn6. BDD7. TDD is dead?8. PHPSpec
![Page 43: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/43.jpg)
TDD is Dead?
Who said that ?! David Heinemeier Hansson (RoR author and Bacecamp founder)
http://martinfowler.com/articles/is-tdd-dead/
http://www.infoq.com/news/2014/06/tdd-dead-controversy
![Page 44: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/44.jpg)
Check List
1. History of TDD2. TDD Cycle of life
1. Red phase2. Green phase3. Refactoring
3. Tests measurement4. TDD Tips5. London vs Brooklyn6. BDD7. TDD is dead?8. PHPSpec
![Page 45: #2 Backend Meetup - Introduction to TDD/BDD](https://reader033.vdocument.in/reader033/viewer/2022061206/54829a49b47959fb0c8b4863/html5/thumbnails/45.jpg)
PHPSpec
Let’s do some live coding!