Page 1
Design for TestabilityAnton Schukin, iOS Developer
twitter: @antonpalich
Page 2
My History2013 - 2015
2015 - Now
Page 3
My History2013 - 2015
2015 - Now
Page 4
320M+ registered users 190 countries 46 languages 50M+ downloads (iOS)
Page 5
Overview1. Unit Testing in Badoo 2. F.I.R.S.T 3. Unit Testing in practice
Page 6
11 developers
iOS Team
Page 7
11 developers, weekly releases: ~ 300 commits ~ 1 000 files changed
iOS Team
Page 8
11 developers, weekly releases: ~ 300 commits ~ 1 000 files changed ~ 50 000 insertions ~ 63 000 deletions (Legacy code removals)
iOS Team
Page 9
New Features
Changes
Page 10
New Features Bug fixing
Changes
Page 11
New Features Bug fixing Technical debts
Changes
Page 12
Code Coverage
20
25
30
35
40
Sep Oct Nov Dec Jan Feb Mar Apr May June July Aug Sep
from 23.47% to 36.47% (70675 / 193726 lines)
Page 13
Find problem earlier
Unit Testing - WHY?
Page 14
Find problem earlier Regression tests for changes
Unit Testing - WHY?
Page 15
Find problem earlier Regression tests for changes Live documentation
Unit Testing - WHY?
Page 16
Unit Testing - WHAT?
Page 17
Unit Testing - WHAT?
State Interaction with dependencies
Page 18
Unit Testing - WHAT?
State Interaction with dependencies
MVP MVCMVVM VIPER
Page 19
F.I.R.S.T*
• Fast
• Independent
• Repeatable
• Self-validating
• Timely
*Robert C. Martin «Clean Code»
Page 20
Fast
1s 100ms 10ms
100 tests 1m 40s 10s 1s
1000 tests 16m 40s 1m 40s 10s
4000 tests 1h 6m 40s 6m 40s 40s
Page 21
Fast
1s 100ms 10ms
100 tests 1m 40s 10s 1s
1000 tests 16m 40s 1m 40s 10s
4000 tests 1h 6m 40s 6m 40s 40s
Page 22
Fast
3877 tests in 79.66s (~49ms per test)*
* MacBook Pro Retina (Early 2013), 2.7 GHz i7, 16GB 1600 MHz
Page 23
Independent
T1
Sandbox
T2 T3 T4
+[NSUserDefaults standardUserDefaults]
Page 24
Independent
T1
Sandbox
Mock
T2
Sandbox
Mock
T3
Sandbox
Mock
T4
Sandbox
Mock
Page 25
Repeatable
T1
Dev 1
Result
T1
Dev 2
Result
T1
CI 1
Result
T1
CI 2
Result== == ==
Page 26
Self-validating
PASSED OR FAILED
Page 28
Timely
Dev PolishingTest after code
for code coverage
Page 29
Timely
Dev Polishing
Dev PolishingTest after code
for code coverage
Test after code for value
Page 30
Timely
Dev
Dev Polishing
Dev PolishingTest after code
for code coverage
Test after code for value
TDD
Page 31
New Feature
Download user photos
Page 32
New Feature
Download user photos Store compressed and original photos
Page 33
New Feature
Download user photos Store compressed and original photos Do it no more than every four hours
Page 34
New Feature
Download user photos Store compressed and original photos Do it no more than every four hours Do it when your app becomes active
Page 35
Code Example
https://github.com/AntonPalich/NSSpain16Example
Page 36
Conclusion
Think about interfaces first
Page 37
Conclusion
Think about interfaces first Unit tests is your friend
Page 38
Conclusion
Think about interfaces first Unit tests is your friend TDD saves developer time
Page 39
Conclusion
Think about interfaces first Unit tests is your friend TDD saves developer time TAD (Test after development) also fine
Page 40
Thank you! We’re hiring
twitter: @BadooTech github.com/Badoo