
#014 - Building the Best Tools and Tests with The Primeagen
Backend Banter
Separate to Simplify: Testable Code Begins with Clear Functions
Build functions with the mindset that they should be unit testable without relying on mocks. Mocks complicate testing and indicate poor code design; they suggest you've mixed input/output operations within your function. Instead, separate concerns by creating distinct functions for data retrieval and data processing. This approach enhances testability, as functions can be tested independently by providing expected inputs and outputs. Aim for clear separation of logic to simplify testing, enabling straightforward black box testing without unnecessary complexity. If a function isn't easily manageable within three attempts, it likely requires a dedicated test.
00:00
Transcript
Play full episode
Remember Everything You Learn from Podcasts
Save insights instantly, chat with episodes, and build lasting knowledge - all powered by AI.