Code coverage refers to
the amount of code covered
by test cases
Slide 52
Slide 52 text
The tragedy of
100% code coverage
Slide 53
Slide 53 text
assertEquals($expected, $result);
}
}
Slide 54
Slide 54 text
No content
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
No content
Slide 57
Slide 57 text
No content
Slide 58
Slide 58 text
No content
Slide 59
Slide 59 text
Best Practices
Slide 60
Slide 60 text
Keep the unit small
Minimize assertions
Start with the failing test case
Fast running tests
Avoid fragile tests
Rerun all test cases on each failure
Don’t introduce dependencies between tests
Follow standard naming conventions
Use mock objects
Slide 61
Slide 61 text
The Bad Parts
Slide 62
Slide 62 text
Hard to apply to existing legacy code
Requirements misinterpretations
False sense of security
How many tests should you write?
Complex scenarios
Rapidly changing requirements
Not having enough knowledge on unit testing and refactoring
Restricted portability
Writer/Reader with technical background
Slide 63
Slide 63 text
Behavior-driven development
Slide 64
Slide 64 text
Behavioural Test Unit Test
Slide 65
Slide 65 text
No content
Slide 66
Slide 66 text
Scenario: Dispense $50 cash in multiple denominations
Given I have $100 in my account
And I have a card with the PIN 1234
And I push my card into the machine
And I enter 1234 for my PIN
And I push the button next to Withdrawal
And I push the button next to Checking
When I push the button next to $50
Then a $20 bill should be ejected by the cash dispenser
And a $20 bill should be ejected by the cash dispenser
And a $10 bill should be ejected by the cash dispenser
Slide 67
Slide 67 text
Scenario: Dispense $50 cash in multiple denominations
Given I have $100 in my account
And I have a card with the PIN 1234
And I push my card into the machine
And I enter 1234 for my PIN
And I push the button next to Withdrawal
And I push the button next to Checking
When I push the button next to $50
Then a $20 bill should be ejected by the cash dispenser
And a $20 bill should be ejected by the cash dispenser
And a $10 bill should be ejected by the cash dispenser
Slide 68
Slide 68 text
Scenario: Dispense $50 cash in multiple denominations
Given I have $100 in my account
And I have a card with the PIN 1234
And I push my card into the machine
And I enter 1234 for my PIN
And I push the button next to Withdrawal
And I push the button next to Checking
When I push the button next to $50
Then a $20 bill should be ejected by the cash dispenser
And a $20 bill should be ejected by the cash dispenser
And a $10 bill should be ejected by the cash dispenser
Slide 69
Slide 69 text
Scenario: Dispense $50 cash in multiple denominations
Given I have $100 in my account
And I have a card with the PIN 1234
And I push my card into the machine
And I enter 1234 for my PIN
And I push the button next to Withdrawal
And I push the button next to Checking
When I push the button next to $50
Then a $20 bill should be ejected by the cash dispenser
And a $20 bill should be ejected by the cash dispenser
And a $10 bill should be ejected by the cash dispenser
Slide 70
Slide 70 text
Scenario: Dispense $50 cash in multiple denominations
Given I have $100 in my account
And I have a card with the PIN 1234
And I push my card into the machine
And I enter 1234 for my PIN
And I push the button next to Withdrawal
And I push the button next to Checking
When I push the button next to $50
Then a $20 bill should be ejected by the cash dispenser
And a $20 bill should be ejected by the cash dispenser
And a $10 bill should be ejected by the cash dispenser
Slide 71
Slide 71 text
TDD vs BDD
Slide 72
Slide 72 text
TDD
Hard to apply to existing legacy code
Inside out
Fast execution time
“That is wrong”
Doing the thing right
Technical writer/reader
Low case coverage
Poor maintainability
Easy to apply to existing legacy code
Outside in
Slow execution time
“Something is wrong”
Doing the right thing
Business writer/reader
High case coverage
High maintainability
BDD
Slide 73
Slide 73 text
TDD or BDD?
Slide 74
Slide 74 text
Final Thoughts
Slide 75
Slide 75 text
No content
Slide 76
Slide 76 text
“It’s a skill!
Learn it by using it”
Slide 77
Slide 77 text
Do you release with failing tests?
Does it depends?
Slide 78
Slide 78 text
References
Test Driven Development: By Example by Kent Beck (2002)
Refactoring by Kent Beck and Martin Fowler (1999)
Succeeding with Agile by Mike Cohn (2009)
Working Effectively with Unit Tests by Jay Fields (2014)
The Art of Unit Testing by Roy Osherove (2013)
Software Reliability: Principles and Practices by Glenford J. Myers (1976)