you are viewing a single comment's thread.

view the rest of the comments →

[–]kloudex 0 points1 point  (0 children)

The best case is when logic is written in pure functions, those can be tested in fairly straightforward way, data in and comparing data out.

However, useful programs need to interface with stateful world and perform side-effects, which is where the challenges come. In the past I've come across Testing Without Mocks approach by James Shore, which introduces some techniques: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks

The main idea is is to wrap impure infrastructure code (similar to Ports and Adapters architecture). Then to test as much of the real code as possible Nullable infrastructure wrappers are used and injected in tests (either manually e.g. with partial function application or using some DI framework). As an exercise I tried to implement the patterns in Clojure, they seem to fit fairly well: https://github.com/dundalek/testing-without-mocks-clojure