@barryosull 2022
Introduction to test pain
Types of pain & what they're telling you
Live refactoring of painful test code
Questions
Automated testing
DDD tactical patterns
Basic refactoring
Ports and Adapters
Illegibility
Excessive expects calls
Seeding DB data everywhere
Magic injection of objects and data
Chains of
mocks
Partial mocks
Can't read the test code:
Seeding DB data everywhere:
Chains of mocks:
Too many details; refactor & encapsulate
DB is tightly coupled to your application(s)/domain(s)
Missing encapsulation boundaries
Magic injection of objects and data:
Have to use partial mocks:
Excessive expects calls:
System not written to be testable, needs DI
Behaviour & awkward details are muddled together
Behaviour and side-effects are interwoven
Naming and explicitness:
Bring clarity by naming and grouping concepts
Given/When/Then:
Make it clear, remove noise and confusing details
Separation of concerns & encapsulation:
Separate what you're doing from how you're doing it
Automatic refactoring tools:
Rename variable/method, extract method/class
Setup/Dependency factories
Testcases
Given/Expectations/When
Verifications
Data Factories
Solution: Dependency Injections via Constructor
Pain: Magic injection
Solution: Repositories
Pain: DB Seeding
Solution: ValueObjects
& HTTP Adapter
Pain: Validation & Primitives
+
Event
Repostiory
Event
Broadcaster/
Listener
What the Test is Telling Us
Message Service
+
+
+
Unexpressed concepts
Event & Event Listener
VerificationCodeRepository Test & Code
MessageService Test
MessageService
ValueObjects
Ports & Adapters
What the Test is Telling Us
<<interface>>
Request
Requestor
CreateRequest
UpdateRequest
Request & Requestor
HttpClient
UpdateRequestTest
UpdateRequest
@barryosull 2022