refactoring for testability (or how i learned to stop worrying and love failing tests) presented by...
TRANSCRIPT
![Page 1: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/1.jpg)
Refactoring for Testability
(or how I learned to stop worrying and love failing tests)
Presented by Aaron Evans <[email protected]>
![Page 2: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/2.jpg)
Refactoring for Testability
What is refactoring?
What is testability?
How do we do it?
![Page 3: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/3.jpg)
Refactoring for Testability
Why refactor?
My code is good
![Page 4: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/4.jpg)
Refactoring for Testability
Why refactor?
The only constant is change
![Page 5: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/5.jpg)
Refactoring for Testability
User Interface Code
Separate business logic from display logic
Encapsulate implementation details
Don’t tie your code to vendor
Don’t hard code configurationHandle errors
gracefully
Use meaningful variable names
Don’t expose other layers
![Page 6: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/6.jpg)
Refactoring for Testability
Refactoring the UI
Yes, Virginia, there really is display logic
ID tags
Individually testable components
Maintainable UI tests
![Page 7: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/7.jpg)
Refactoring for Testability
Push testing down the stack
Reduce brittle UI tests
Run tests faster
Isolate the system under test
Think about code as individual components
![Page 8: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/8.jpg)
Refactoring for Testability
SOLID
Single Responsibility PrincipleOpen / Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Liskov Substitution Principle
![Page 9: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/9.jpg)
Refactoring for Testability
Refactoring Strategies
http://www.refactoring.com/catalog/
Extract
Change
Encapsulate
Hide
Push down
Move
Consolidate
Expose
Substitute
Pull up
![Page 10: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/10.jpg)
Refactoring for Testability
This…Becomes…
Implementation
![Page 11: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/11.jpg)
Refactoring for Testability
Adding Layers of Abstraction
Composition over Inheritance
Indirection
Reusability
Database Abstraction LayerORM
Domain ModelBusiness Logic
![Page 12: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/12.jpg)
Refactoring for Testability
Simplifying Interfaces
Exposing Functionality
![Page 13: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/13.jpg)
Refactoring for Testability
Decoupling
Presentation and Business Logic
Persistence and Domain Objects
Interface from Implementation
![Page 14: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/14.jpg)
Refactoring for Testability
Dependency Injection
No news is good news
No framework is necessary
Factory pattern
Constructors / Setters / Builders
Loose Coupling
![Page 15: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/15.jpg)
Refactoring for Testability
Extract Interface
Inject Dependency
![Page 16: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/16.jpg)
Refactoring for Testability
Use Mocks
Single Responsibility
![Page 17: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/17.jpg)
Refactoring for Testability
![Page 18: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/18.jpg)
Refactoring for Testability
Reduce Dependencies
![Page 19: Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans](https://reader036.vdocuments.mx/reader036/viewer/2022062517/56649f115503460f94c2417b/html5/thumbnails/19.jpg)
Refactoring for Testability
Coding in business terms
Common domain language
Acceptance criteria
BDD frameworks – RSPEC, Specflow, JBehave