SlideShare a Scribd company logo
1 of 22
Writing Testable Code
Martin Hlavac @m_hlavac
Software Engineer at Wayfair
2
Write tests
Not important
Profit!
Agenda
3 step business model applied to testing
3
• What are unit tests?
Tests
What are tests?
4
• What are unit tests?
Unit tests are tests developers write to prove to themselves,
that the code they are writing works.
It enables them to make changes, without fear of breaking
everything. And they are really what enables teams to make
changes to code aggressively.
Tests
What are tests?
5
• What are unit tests?
Unit tests are tests developers write to prove to themselves,
that the code they are writing works.
It enables them to make changes, without fear of breaking
everything. And they are really what enables teams to make
changes to code aggressively.
Tests
What are tests?
6
• What are unit tests?
Unit tests are tests developers write to prove to themselves,
that the code they are writing works.
It enables them to make changes, without fear of breaking
everything. And they are really what enables teams to make
changes to code aggressively.
Tests
What are tests?
7
• What are unit tests?
Unit tests are tests developers write to prove to themselves,
that the code they are writing works.
It enables them to make changes, without fear of breaking
everything. And they are really what enables teams to make
changes to code aggressively.
Tests
What are tests?
8
• What are unit tests?
Unit tests are tests developers write to prove to themselves,
that the code they are writing works.
It enables them to make changes, without fear of breaking
everything. And they are really what enables teams to make
changes to code aggressively.
Tests
What are tests?
9
17 000 lines file + FEAR = EPIC SLOWDOWN
but
17 000 lines file + Easy changes = DELIVER FAST
Huge code example
Million well hidden dependencies
10
17 000 lines file + FEAR = EPIC SLOWDOWN
but
17 000 lines file + No fear = JUST SLOWDOWN
Huge code example
Million well hidden dependencies
11
17 000 lines file + FEAR = EPIC SLOWDOWN
but
17 000 lines file + No fear = JUST SLOWDOWN
but
100 lines file + No fear = MIGHT BE FASTER
Huge code example
Million well hidden dependencies
12
Different approaches for different problems
Spaghetti, Lasagna, Ravioli can live together
• Different problems require different solutions
• One is not necessarily better than other
• Small script might be just fine as Spaghetti code
• Some framework code can be nice Lasagna
• AWS services are tasty Ravioli
13
Fear slows us down
Regression bugs slow us down
Wrong assumptions slow us down
Manual testing slows us down
Outdated documentation slows us down
Unit tests
what is solves
Unit Tests
Remove fear
Prevent repetitive regression
Validate our assumptions
Are really fast
Document code
Make us faster
14
One more thing
Easy to test == Easy to reuse
Testable code
Easy to reuse
15
What is Repository?
It’s not only database
• Repository per Model, not necessary per table
• Provides a substitution for unit test
• Access to Data Store (not necessary SQL) is done only through Repository
- Never from model
- Never ever from controller
- Never ever ever from template
16
Service Pattern
Specific class that does one thing, in our case this is included in models
• Functional Layer / Business Logic
• Unit tests definately for these cases
• Services should be stateless
• Don’t be afraid to introduce new entity/repository
• NO INTERFACES FOR SERVICES
17
Demo
Let’s dive in!
18
Poisoning the Codebase with Non-Deterministic Factors
Let’s look at what’s they way out of it?
19
Poisoning code with side effects
Bamboo?
20
Write tests
Continous Integration with reliable test suite
Profit!
The hidden ingredient
CI, reliable test suite
21
Questions? Twitter: @m_hlavac
Writing testable code

More Related Content

What's hot

Europython 2015 Testmon
Europython 2015 TestmonEuropython 2015 Testmon
Europython 2015 Testmontib0r
 
Agile Testing in Enterprise: Way to transform - SQA Days 2014
Agile Testing in Enterprise: Way to transform - SQA Days 2014Agile Testing in Enterprise: Way to transform - SQA Days 2014
Agile Testing in Enterprise: Way to transform - SQA Days 2014Andrey Rebrov
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails PresentationPaul Pajo
 
Test Presentation
Test PresentationTest Presentation
Test Presentationsetitesuk
 
TDD on android. Why and How? (Coding Serbia 2019)
TDD on android. Why and How? (Coding Serbia 2019)TDD on android. Why and How? (Coding Serbia 2019)
TDD on android. Why and How? (Coding Serbia 2019)Danny Preussler
 
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang GottesheimPerformance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang GottesheimJAXLondon2014
 
Test Automation Canvas
Test Automation CanvasTest Automation Canvas
Test Automation CanvasAndrey Rebrov
 
Spec By Example or How to teach people talk to each other
Spec By Example or How to teach people talk to each otherSpec By Example or How to teach people talk to each other
Spec By Example or How to teach people talk to each otherAndrey Rebrov
 
How engineering practices help business
How engineering practices help businessHow engineering practices help business
How engineering practices help businessAndrey Rebrov
 
Testing in a continuous delivery world - XP Days Ukraine
Testing in a continuous delivery world  - XP Days UkraineTesting in a continuous delivery world  - XP Days Ukraine
Testing in a continuous delivery world - XP Days UkraineWouter Lagerweij
 
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationLONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationSriram Angajala
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 
The 3 Top Techniques for Web Security Testing Using a Proxy
The 3 Top Techniques for Web Security Testing Using a ProxyThe 3 Top Techniques for Web Security Testing Using a Proxy
The 3 Top Techniques for Web Security Testing Using a ProxyTEST Huddle
 
About Fearless Refactoring Book
About Fearless Refactoring BookAbout Fearless Refactoring Book
About Fearless Refactoring BookPivorak MeetUp
 
I Don't Test Often ...
I Don't Test Often ...I Don't Test Often ...
I Don't Test Often ...Gareth Bowles
 

What's hot (20)

Europython 2015 Testmon
Europython 2015 TestmonEuropython 2015 Testmon
Europython 2015 Testmon
 
Agile Testing in Enterprise: Way to transform - SQA Days 2014
Agile Testing in Enterprise: Way to transform - SQA Days 2014Agile Testing in Enterprise: Way to transform - SQA Days 2014
Agile Testing in Enterprise: Way to transform - SQA Days 2014
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails Presentation
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
Unit testing for project managers
Unit testing for project managersUnit testing for project managers
Unit testing for project managers
 
TDD on android. Why and How? (Coding Serbia 2019)
TDD on android. Why and How? (Coding Serbia 2019)TDD on android. Why and How? (Coding Serbia 2019)
TDD on android. Why and How? (Coding Serbia 2019)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Cypress
CypressCypress
Cypress
 
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang GottesheimPerformance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
 
From document-to-code
From document-to-codeFrom document-to-code
From document-to-code
 
Test Automation Canvas
Test Automation CanvasTest Automation Canvas
Test Automation Canvas
 
Spec By Example or How to teach people talk to each other
Spec By Example or How to teach people talk to each otherSpec By Example or How to teach people talk to each other
Spec By Example or How to teach people talk to each other
 
How engineering practices help business
How engineering practices help businessHow engineering practices help business
How engineering practices help business
 
Testing in a continuous delivery world - XP Days Ukraine
Testing in a continuous delivery world  - XP Days UkraineTesting in a continuous delivery world  - XP Days Ukraine
Testing in a continuous delivery world - XP Days Ukraine
 
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationLONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
The 3 Top Techniques for Web Security Testing Using a Proxy
The 3 Top Techniques for Web Security Testing Using a ProxyThe 3 Top Techniques for Web Security Testing Using a Proxy
The 3 Top Techniques for Web Security Testing Using a Proxy
 
About Fearless Refactoring Book
About Fearless Refactoring BookAbout Fearless Refactoring Book
About Fearless Refactoring Book
 
I Don't Test Often ...
I Don't Test Often ...I Don't Test Often ...
I Don't Test Often ...
 

Similar to Writing testable code

iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Workshop fight legacy code write unit test
Workshop fight legacy code write unit testWorkshop fight legacy code write unit test
Workshop fight legacy code write unit testTung Nguyen Thanh
 
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015][XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]Agile đây Vietnam
 
I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingPeter Presnell
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional ProgrammerDave Cross
 
TDD for Testers Workshop
TDD for Testers WorkshopTDD for Testers Workshop
TDD for Testers WorkshopSarah Usher
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and AutomationMahesh Salaria
 
Agile latvia evening_unit_testing_in_practice
Agile latvia evening_unit_testing_in_practiceAgile latvia evening_unit_testing_in_practice
Agile latvia evening_unit_testing_in_practicedenis Udod
 
Shawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsShawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsQA or the Highway
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with LaravelTyler Johnston
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfEric Selje
 
Do you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well plannedDo you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well plannedJosé San Román A. de Lara
 
A Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoA Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoPsalms Kalu
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptxAmalEldhose2
 
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald BelchamGetting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham.NET Conf UY
 
[Php vigo][talk] unit testing sucks ( and it's your fault )
[Php vigo][talk] unit testing sucks ( and it's your fault )[Php vigo][talk] unit testing sucks ( and it's your fault )
[Php vigo][talk] unit testing sucks ( and it's your fault )PHP Vigo
 
Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 

Similar to Writing testable code (20)

iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Workshop fight legacy code write unit test
Workshop fight legacy code write unit testWorkshop fight legacy code write unit test
Workshop fight legacy code write unit test
 
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015][XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
 
Let's test!
Let's test!Let's test!
Let's test!
 
I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application Testing
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
TDD for Testers Workshop
TDD for Testers WorkshopTDD for Testers Workshop
TDD for Testers Workshop
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
Agile latvia evening_unit_testing_in_practice
Agile latvia evening_unit_testing_in_practiceAgile latvia evening_unit_testing_in_practice
Agile latvia evening_unit_testing_in_practice
 
Shawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applicationsShawn Wallace - Test automation in brownfield applications
Shawn Wallace - Test automation in brownfield applications
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
 
Intro to Devops
Intro to DevopsIntro to Devops
Intro to Devops
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
Do you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well plannedDo you have a #bug? Your unit tests are not well planned
Do you have a #bug? Your unit tests are not well planned
 
A Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoA Beginer's Guide to testing in Django
A Beginer's Guide to testing in Django
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald BelchamGetting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
 
[Php vigo][talk] unit testing sucks ( and it's your fault )
[Php vigo][talk] unit testing sucks ( and it's your fault )[Php vigo][talk] unit testing sucks ( and it's your fault )
[Php vigo][talk] unit testing sucks ( and it's your fault )
 
Unit testing
Unit testingUnit testing
Unit testing
 

Recently uploaded

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 

Recently uploaded (20)

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 

Writing testable code

  • 1. Writing Testable Code Martin Hlavac @m_hlavac Software Engineer at Wayfair
  • 2. 2 Write tests Not important Profit! Agenda 3 step business model applied to testing
  • 3. 3 • What are unit tests? Tests What are tests?
  • 4. 4 • What are unit tests? Unit tests are tests developers write to prove to themselves, that the code they are writing works. It enables them to make changes, without fear of breaking everything. And they are really what enables teams to make changes to code aggressively. Tests What are tests?
  • 5. 5 • What are unit tests? Unit tests are tests developers write to prove to themselves, that the code they are writing works. It enables them to make changes, without fear of breaking everything. And they are really what enables teams to make changes to code aggressively. Tests What are tests?
  • 6. 6 • What are unit tests? Unit tests are tests developers write to prove to themselves, that the code they are writing works. It enables them to make changes, without fear of breaking everything. And they are really what enables teams to make changes to code aggressively. Tests What are tests?
  • 7. 7 • What are unit tests? Unit tests are tests developers write to prove to themselves, that the code they are writing works. It enables them to make changes, without fear of breaking everything. And they are really what enables teams to make changes to code aggressively. Tests What are tests?
  • 8. 8 • What are unit tests? Unit tests are tests developers write to prove to themselves, that the code they are writing works. It enables them to make changes, without fear of breaking everything. And they are really what enables teams to make changes to code aggressively. Tests What are tests?
  • 9. 9 17 000 lines file + FEAR = EPIC SLOWDOWN but 17 000 lines file + Easy changes = DELIVER FAST Huge code example Million well hidden dependencies
  • 10. 10 17 000 lines file + FEAR = EPIC SLOWDOWN but 17 000 lines file + No fear = JUST SLOWDOWN Huge code example Million well hidden dependencies
  • 11. 11 17 000 lines file + FEAR = EPIC SLOWDOWN but 17 000 lines file + No fear = JUST SLOWDOWN but 100 lines file + No fear = MIGHT BE FASTER Huge code example Million well hidden dependencies
  • 12. 12 Different approaches for different problems Spaghetti, Lasagna, Ravioli can live together • Different problems require different solutions • One is not necessarily better than other • Small script might be just fine as Spaghetti code • Some framework code can be nice Lasagna • AWS services are tasty Ravioli
  • 13. 13 Fear slows us down Regression bugs slow us down Wrong assumptions slow us down Manual testing slows us down Outdated documentation slows us down Unit tests what is solves Unit Tests Remove fear Prevent repetitive regression Validate our assumptions Are really fast Document code Make us faster
  • 14. 14 One more thing Easy to test == Easy to reuse Testable code Easy to reuse
  • 15. 15 What is Repository? It’s not only database • Repository per Model, not necessary per table • Provides a substitution for unit test • Access to Data Store (not necessary SQL) is done only through Repository - Never from model - Never ever from controller - Never ever ever from template
  • 16. 16 Service Pattern Specific class that does one thing, in our case this is included in models • Functional Layer / Business Logic • Unit tests definately for these cases • Services should be stateless • Don’t be afraid to introduce new entity/repository • NO INTERFACES FOR SERVICES
  • 18. 18 Poisoning the Codebase with Non-Deterministic Factors Let’s look at what’s they way out of it?
  • 19. 19 Poisoning code with side effects Bamboo?
  • 20. 20 Write tests Continous Integration with reliable test suite Profit! The hidden ingredient CI, reliable test suite