Simplifying Tests by Extracting Side-Effects

25-Feb-2021 1232
Test-driven development, object-oriented design, and functional programming converge on some similar ideas.Functional programming gives us a mental model that can be helpful when looking at unit testing our object-oriented code. In particular, it gives us two terms:Pure functions - these are deterministic methods with explicit inputs and outputs (e.g. no implicit dependency on the system clock). This kind of method is the easiest to test.Side-effects - Any source of inputs or outputs for a method that are not part of the arguments or return value. Examples include calls to Time.now, or writing the output to a file. These types of methods are non-deterministic, which makes them trickier to test and usually involves some mocking or stubbing.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle