10 ms·
If you can write very pure code, mocking is not needed. For example, a function for a database call could return a closure of what to do given a cursor into the
by bonobo3000 11y ago
If you can write very pure code, mocking is not needed. For example, a function for a database call could return a closure of what to do given a cursor into the database, or a SQL query which can be tested. The side-effecting functions themselves would just create a connection to a db or network host and do exactly what is prescribed in the request, making them simple enough to not need to unit test.
This is one of the big benefits of FP and pure functions really. I'm sure there would be practicalities that get in the way of doing this cleanly for all code, but it can go a surprisingly long way. The idea is to write a completely pure core and restrict input/output to be through a few small and obviously correct functions.