December 2019
Intermediate to advanced
248 pages
5h 34m
English
All of our tests are inside our functional core. In the core, calling a function with the same arguments will almost always result in the same output. That word “almost” is a killer because our whole strategy involves comparing our expectations to actual values. When we can’t have expectations from run to run, we must change our approach.
Sometimes, functions are not perfectly pure. Functions that create timestamps or random numbers are famously difficult to test. We have both types of functions in our codebase. For example, recall the response test:
| | test "a timestamp is added at build time", %{right: response} do |
| | assert %DateTime{ } = response.timestamp |
| | assert response.timestamp < DateTime.utc_now |
| | end |
Read now
Unlock full access