Video: http://bit.ly/tdd-talk-2
This slideshow has links, download the PDF to click them.
While this presentation touches on PHP a fair bit, it does make parallels to other ecosystems such as Java and C#/.Net, building toward an approach for building Web Applications in a Test-Driven way.
Have you ever jumped into a legacy software project and gotten to a point where it takes a near-infinite amount of time to deliver any new feature, for fear of breaking legacy functionality you’ve barely begun to understand? Software Engineering can be extremely difficult and maddening. But it doesn’t have to be. We will explore leveraging TDD and OOP principles to make Software Engineering fun again.
Coding exercises supporting this presentation are available here:
http://bit.ly/tdd-vids
Better and Faster: A Journey Toward Clean Code and Enjoyment
1.
2. A Journey Toward Clean
Code and Enjoyment
Impact and Logistics of
Software Craftsmanship on
True Business Agility
3. A Journey Toward Clean
Code and Enjoyment
Impact and Logistics of
Software Craftsmanship on
True Business Agility
https://www.linkedin.com/in/chrisholland
https://github.com/elchris
@chrisholland
16. Taking Away Our Fun
❖ Inheriting Someone else’s code
❖ Having a hard time understanding how a system works
❖ Breaking old things when building new things
❖ Testing our work as much as we ought to
21. A Word about “Agility" …
We need to be more …
Agile!
22. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
23. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
24. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
25. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
26. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
Build MVC
Applications
Faster
27. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
Build MVC
Applications
Faster
MVC Frameworks
28. A Word about “Agility" …
Underlying Issue:
…
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
Build MVC
Applications
Faster
MVC Frameworks
29. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
Build MVC
Applications
Faster
MVC Frameworks
Underlying Issue:
…
30. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
Build MVC
Applications
Faster
MVC Frameworks
Underlying Issue:
…
31. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
Build MVC
Applications
Faster
MVC Frameworks
Underlying Issue:
…
32. A Word about “Agility" …
Re-inventing Project
Management
&
Task-Planning
Scrum / Kanban
Scripting Integration
“Integration Hell”
CI / CD
Build MVC
Applications
Faster
MVC Frameworks
Underlying Issue:
…
Bad Software !
33. A Word about “Agility” …
❖ https://martinfowler.com/bliki/FlaccidScrum.html
75. Flaccid OOP
❖ Indiscriminate use of OOP Constructs
❖ Random instantiation of Classes
❖ Unpredictable System Coupling
❖ Unpredictable System State
❖ Law of Demeter Violations (Past Meetup)
97. Beyond MVC: CSRVCED
❖ Yellow Zone: “Irrelevant”
❖ Very thin: 1% of code-base. If that.
❖ Coupled to Transport: HTTP / HTML
❖ Coupled to Framework
98. Beyond MVC: CSRVCED
❖ Green Zone: “What Matters”
❖ 99%+ of code-base
❖ Transport-Agnostic
❖ Framework-Agnostic
99. Web App: Repositories
❖ Can be backed by any data store
❖ Swappable implementation as needs evolve:
❖ RDBMS -> NoSQL: Data Storage Scalability
❖ ORM -> Raw SQL: Increase Performance
100. Web App. Architectures
❖ Watch: http://bit.ly/clean-architecture-video
❖ Read: http://bit.ly/clean-architecture
101. Bad Code vs Agility
Better Code: Enablers
Empowering OOP
Web App. Architectures
TDD: Better Fuels Faster
102. Bad Code vs Agility
Better Code: Enablers
Empowering OOP
Web App. Architectures
TDD: Better Fuels Faster
115. TDD vs Unit Tests
❖ After the Fact Testing: “Now I have to cover my code”
❖ Test-Driven Development: “I code to my assertions”
116. TDD: Web Applications Challenges
❖ Most TDD Tutorials focus on simple algorithmic
problems.
❖ And yet, Web Apps:
❖ Have several Architectural Layers
❖ (Should) Have many Classes
❖ Are heavily Data/IO Driven
122. Web Apps: Time Wasted
❖ While Building Things:
❖ Set-up local DB
❖ Scaffold / bootstrap basic UI
❖ Write Code
❖ Use debugger to step thru code
❖ Use logging to trace behavior & debug issues
123. Web Apps: Time Wasted
❖ While Testing Things:
❖ Click UI to get application into given state
❖ Visually inspect database records to verify behavior
❖ Manually modify DB records to jump to state
❖ Break things as you build new things
124. Web Apps: Old Workflow
❖ All Activities marked in RED are throw-away activities.
❖ They are manual and repetitive
❖ … relevant only once
138. Web Apps TDD: Tooling
❖ xUnit
❖ ORM w/ Code-First Data Mapper Pattern
❖ In-Memory DB
❖ …
139. Web Apps TDD: PHP
❖ xUnit
❖ PHPUnit
❖ ORM w/ Code-First Data Mapper Pattern
❖ Doctrine ORM
❖ In-Memory DB
❖ SQLite
140. Web Apps TDD: Java
❖ xUnit
❖ jUnit
❖ ORM w/ Code-First Data Mapper Pattern
❖ Hibernate
❖ In-Memory DB
❖ HSQLDB
141. Web Apps TDD: .Net/C#
❖ xUnit
❖ NUnit
❖ ORM w/ Code-First Data Mapper Pattern
❖ Entity Framework or NHibernate
❖ In-Memory DB
❖ SQL CE
142. Web Apps TDD: Covenants
❖ Commit to TDD and enforce with:
❖ Tooling to ensure 100% coverage, at all times
❖ Peer code reviews to verify that all tests have
meaningful assertions
143. Web Apps TDD: Covenants
❖ You don’t want:
❖ Less than 100% coverage. TDD gives you that for free.
Going below 100% means someone isn’t doing TDD.
❖ Code that is 100% covered with meaningless
assertions. This also means someone isn’t doing TDD.
169. Map URI Routes to Service Methods
Build UI
Concurrently
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
170. Map URI Routes to Service Methods
Generate SQL Migration from Entity Graph
Build UI
Concurrently
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
171. Map URI Routes to Service Methods
Generate SQL Migration from Entity Graph
Run SQL Migrations against Local RDBMS
Build UI
Concurrently
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
172. Map URI Routes to Service Methods
Generate SQL Migration from Entity Graph
Run SQL Migrations against Local RDBMS
Build UI
Concurrently
Test Application thru the UI
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
TDD Service
TDD
Repo(s)
173. TDD Service
TDD
Repo
TDD Service
TDD
Repo
TDD Service
TDD
Repo
Map URI Routes to Service Methods
Generate SQL Migration from Entity Graph
Run SQL Migrations against Local RDBMS
Build UI
Concurrently
Test Application thru the UI
Zone 1
Zone 2
174. TDD Service
TDD
Repo
TDD Service
TDD
Repo
TDD Service
TDD
Repo
Zone 1
Map URI Routes to Service Methods
Generate SQL Migration from Entity Graph
Run SQL Migrations against Local RDBMS
Build UI
Concurrently
Test Application thru the UI
Zone 2
175. TDD Service
TDD
Repo
TDD Service
TDD
Repo
TDD Service
TDD
Repo
Zone 1
Map URI Routes to Service Methods
Generate SQL Migration from Entity Graph
Run SQL Migrations against Local RDBMS
Build UI
Concurrently
Test Application thru the UI
Zone 2
Decoupled
176. TDD Workflow Advantages
❖ Implement Most Business Logic in Zone 1
❖ Without having to depend on Zone 2
❖ Rapid, Localized TDD iterations in Zone 1
217. Web Apps TDD: Benefits
❖ Keep UI Workflows Decoupled …
❖ … from solving Business Problems
218. Web Apps TDD: Benefits
❖ Get in the Zone, Stay in it.
219. Web Apps TDD: Benefits
❖ Easy to get back into the Zone after interruption
❖ Last Test you wrote is your “anchor”
220. Web Apps TDD: Benefits
❖ No need to worry about “Optimal Design”
❖ Code can always be improved.
❖ Because covered.
221. Web Apps TDD: Benefits
❖ No need to worry about “Optimal Design”
❖ Code can always be improved.
❖ Because covered.
Implement First, Optimize Later
222. Web Apps TDD: Benefits
❖ 100% code coverage “For Free”
❖ Sustained Velocity => Agility
❖ Unit Tests are the Living Documentation of our App