SlideShare uma empresa Scribd logo
1 de 45
INTRODUCTION TO
TEST DRIVEN
DEVELOPMENT
tw: @MaciejGrajcarek
Check List
1. History of TDD
2. TDD Cycles
3. BDD
4. TDD is dead?
5. PHPSpec
Who needs tests anyway?
Who needs tests anyway? Bugs
killers!
Technical Debt
Technical Debt
Where it all began
Waterfall Model
Winston W. Royce (1970)
Where it all began
Agile – best friend of TDD
- Adaptive vs Predictive
- Iterative vs Waterfall
2001 – Agile Manifesto
Where it all began
Scrum Cicle
Analysis
Programming
Testing
Acceptance
Where it all began
„Test Driven Development: By
Example” – Kent Beck (2003)
Check List
1. History of TDD
2. TDD Cycle of life
3. BDD
4. TDD is dead?
5. PHPSpec
TDD Cycle of life
Failing Test
Pass testRefactoring
TDD Cycle of life
Failing Test
•Make test
compile
•Make sure it
doesn’t pass
First simple failing test
function checkSumTest()
{
$a = 5;
$b = 4;
$calculator = new Calculator();
$sum = $calculator->sum($a, $b);
$this->assertEqual(9, $sum);
}
TDD Cycle of life
Pass test
• Fake It (Till You
Make It)
• Type The Obvious
Implementation
• Triangulation
Fake It (Till You Make It)
class Calculator
{
function sum($a, $b)
{
return 9;
}
}
Type The Obvious
Implementation
class Calculator
{
function sum($a, $b)
{
$sum = $a + $b;
return $sum;
}
}
Triangulation
At least two points needed to find a
location.
Triangulation
//Test 1
$sum = $calculator->sum($a, $b);
$this->assertEqual(9, $sum);
class Calculator
{
function sum($a, $b)
{
$sum = $a + $b;
return $sum;
}
}
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;
}
}
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);
Triangulation
class Calculator
{
function sum()
{
$elements = func_get_args();
$sum = 0;
foreach ($elements as $el) {
$sum += $el;
}
return $sum;
}
}
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);
Triangulation
//Final test
$sum = $calculator->sum(4, 5, 7, 1);
$this->assertEqual(17, $sum);
TDD Cycle of life
Refactoring
•KISS
•DRY
Maintainability, Flexibility, Portability, Reusability,
Readability, Scalability, Testability, Understandability
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
TDD Cycle of life
Failing Test
Pass testRefactoring
Check List
1. History of TDD
2. TDD Cycle of life
1. Red phase
2. Green phase
3. Refactoring
3. Tests measurement
4. TDD Tips
5. BDD
6. TDD is dead?
7. PHPSpec
Tests measurement
1. Code Coverage
2. Underlay Defects
- 100 % code coverage != Error Free
- Vendor code should have 100% code
coverage, but yours not necessarily
TDD Tips
1. Create a check list of tests
TDD Tips
1. Create a check list of tests
2. Small step approach during
refactorization (or larger when fealing
comfortable)
TDD Tips
1. Create a check list of tests
2. Small step approach during refactorization (or
larger when fealing comfortable)
3. Add problems to the list, instead of
resolving them immediately
TDD Tips
1. Create a check list of tests
2. 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
TDD Tips
1. Create a check list of tests
2. 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!)
TDD Tips
1. Create a check list of tests
2. 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!)
6. Tests should be fast and isolated
TDD Tips
1. Create a check list of tests
2. 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!)
6. Tests should be fast and isolated
7. Test only public
TDD Tips
1. Create a check list of tests
2. 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!)
6. Tests should be fast and isolated
7. Test only public
8. Write your own tests, don’t wait for a
teammate
London vs Brooklyn School of
TDD
Is it all about Mocks?
Check List
1. History of TDD
2. TDD Cycle of life
1. Red phase
2. Green phase
3. Refactoring
3. Tests measurement
4. TDD Tips
5. London vs Brooklyn
6. BDD
7. TDD is dead?
8. PHPSpec
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
Check List
1. History of TDD
2. TDD Cycle of life
1. Red phase
2. Green phase
3. Refactoring
3. Tests measurement
4. TDD Tips
5. London vs Brooklyn
6. BDD
7. TDD is dead?
8. PHPSpec
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
Check List
1. History of TDD
2. TDD Cycle of life
1. Red phase
2. Green phase
3. Refactoring
3. Tests measurement
4. TDD Tips
5. London vs Brooklyn
6. BDD
7. TDD is dead?
8. PHPSpec
PHPSpec
Let’s do some live coding!

Mais conteúdo relacionado

Destaque

Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)Alan Dean
 
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDDAlex Sharp
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefAhmed Shreef
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoElad Elrom
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
BDD in Action: Building Software Right and Building the Right Software
BDD in Action: Building Software Right and Building the Right SoftwareBDD in Action: Building Software Right and Building the Right Software
BDD in Action: Building Software Right and Building the Right SoftwareJohn Ferguson Smart Limited
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentTung Nguyen Thanh
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven developmenttoteb5
 
BDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationBDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationJohn Ferguson Smart Limited
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)Brian Rasmussen
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Zohirul Alam Tiemoon
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 

Destaque (18)

Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)
 
BDD Anti-patterns
BDD Anti-patternsBDD Anti-patterns
BDD Anti-patterns
 
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDD
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
BDD in Action: Building Software Right and Building the Right Software
BDD in Action: Building Software Right and Building the Right SoftwareBDD in Action: Building Software Right and Building the Right Software
BDD in Action: Building Software Right and Building the Right Software
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
TDD Overview
TDD OverviewTDD Overview
TDD Overview
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
 
BDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world applicationBDD in Action – principles, practices and real-world application
BDD in Action – principles, practices and real-world application
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
BDD in Action - building software that matters
BDD in Action - building software that mattersBDD in Action - building software that matters
BDD in Action - building software that matters
 
BDD & Behat
BDD & BehatBDD & Behat
BDD & Behat
 

Último

WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 

Último (20)

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

#2 Backend Meetup - Introduction to TDD/BDD

  • 2. Check List 1. History of TDD 2. TDD Cycles 3. BDD 4. TDD is dead? 5. PHPSpec
  • 3. Who needs tests anyway?
  • 4. Who needs tests anyway? Bugs killers!
  • 7. Where it all began Waterfall Model Winston W. Royce (1970)
  • 8. Where it all began Agile – best friend of TDD - Adaptive vs Predictive - Iterative vs Waterfall 2001 – Agile Manifesto
  • 9. Where it all began Scrum Cicle Analysis Programming Testing Acceptance
  • 10. Where it all began „Test Driven Development: By Example” – Kent Beck (2003)
  • 11. Check List 1. History of TDD 2. TDD Cycle of life 3. BDD 4. TDD is dead? 5. PHPSpec
  • 12. TDD Cycle of life Failing Test Pass testRefactoring
  • 13. TDD Cycle of life Failing Test •Make test compile •Make sure it doesn’t pass
  • 14. First simple failing test function checkSumTest() { $a = 5; $b = 4; $calculator = new Calculator(); $sum = $calculator->sum($a, $b); $this->assertEqual(9, $sum); }
  • 15. TDD Cycle of life Pass test • Fake It (Till You Make It) • Type The Obvious Implementation • Triangulation
  • 16. Fake It (Till You Make It) class Calculator { function sum($a, $b) { return 9; } }
  • 17. Type The Obvious Implementation class Calculator { function sum($a, $b) { $sum = $a + $b; return $sum; } }
  • 18. Triangulation At least two points needed to find a location.
  • 19. Triangulation //Test 1 $sum = $calculator->sum($a, $b); $this->assertEqual(9, $sum); class Calculator { function sum($a, $b) { $sum = $a + $b; return $sum; } }
  • 20. 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; } }
  • 21. 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);
  • 22. Triangulation class Calculator { function sum() { $elements = func_get_args(); $sum = 0; foreach ($elements as $el) { $sum += $el; } return $sum; } }
  • 23. 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);
  • 24. Triangulation //Final test $sum = $calculator->sum(4, 5, 7, 1); $this->assertEqual(17, $sum);
  • 25. TDD Cycle of life Refactoring •KISS •DRY
  • 26. Maintainability, Flexibility, Portability, Reusability, Readability, Scalability, Testability, Understandability
  • 27. 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
  • 28. TDD Cycle of life Failing Test Pass testRefactoring
  • 29. Check List 1. History of TDD 2. TDD Cycle of life 1. Red phase 2. Green phase 3. Refactoring 3. Tests measurement 4. TDD Tips 5. BDD 6. TDD is dead? 7. PHPSpec
  • 30. Tests measurement 1. Code Coverage 2. Underlay Defects - 100 % code coverage != Error Free - Vendor code should have 100% code coverage, but yours not necessarily
  • 31. TDD Tips 1. Create a check list of tests
  • 32. TDD Tips 1. Create a check list of tests 2. Small step approach during refactorization (or larger when fealing comfortable)
  • 33. TDD Tips 1. Create a check list of tests 2. Small step approach during refactorization (or larger when fealing comfortable) 3. Add problems to the list, instead of resolving them immediately
  • 34. TDD Tips 1. Create a check list of tests 2. 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
  • 35. TDD Tips 1. Create a check list of tests 2. 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!)
  • 36. TDD Tips 1. Create a check list of tests 2. 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!) 6. Tests should be fast and isolated
  • 37. TDD Tips 1. Create a check list of tests 2. 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!) 6. Tests should be fast and isolated 7. Test only public
  • 38. TDD Tips 1. Create a check list of tests 2. 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!) 6. Tests should be fast and isolated 7. Test only public 8. Write your own tests, don’t wait for a teammate
  • 39. London vs Brooklyn School of TDD Is it all about Mocks?
  • 40. Check List 1. History of TDD 2. TDD Cycle of life 1. Red phase 2. Green phase 3. Refactoring 3. Tests measurement 4. TDD Tips 5. London vs Brooklyn 6. BDD 7. TDD is dead? 8. PHPSpec
  • 41. 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
  • 42. Check List 1. History of TDD 2. TDD Cycle of life 1. Red phase 2. Green phase 3. Refactoring 3. Tests measurement 4. TDD Tips 5. London vs Brooklyn 6. BDD 7. TDD is dead? 8. PHPSpec
  • 43. 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
  • 44. Check List 1. History of TDD 2. TDD Cycle of life 1. Red phase 2. Green phase 3. Refactoring 3. Tests measurement 4. TDD Tips 5. London vs Brooklyn 6. BDD 7. TDD is dead? 8. PHPSpec
  • 45. PHPSpec Let’s do some live coding!

Notas do Editor

  1. Bugs killing Mege request
  2. Bugs killing Mege request
  3. Bugs killing Mege request