beginners

2025-08-21T16:17:42.323559Z

Not sure if this is a beginner question but... I started writing Clojure on a daily basis for study, and I created a small application with some third party integrations. I'm searching for books regarding to how to write testable code, do you have any suggestions?

st 2025-08-22T07:43:18.060109Z

I'd say general principles apply in Clojure: • https://tidyfirst.substack.com/p/desirable-unit-testshttps://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530 There are different opinions regarding tests in Clojure community, and you will want to find your workflow. For example, quick swap between throwable experiment with code in REPL and proper unit tests, comment section in your namespace, ... @neumann has good podcast episode where he mentions his flow. https://clojuredesign.club/episode/ You also have the freedom to mock/stub in Clojure which shouldn't be overused...

gaverhae 2025-08-22T15:50:12.022529Z

Not exactly an answer to your question, but I'd very strongly recommend keeping a (small) terminal with your tests running visible at all times; something like lein test-refresh or watchexec -w src -w test -- clj -X:test. Apart from that, try to write the vast majority of your code as pure functions, as testing those is easy.

2025-08-22T16:51:50.587679Z

@gaverhae I'm currently using an approach where I have another terminal running using kaocha with --watch flag. About writing pure functions, I'm still a little bit confused about the best approach do that and then wire up all the functions in the context of a web application (I came from a Ruby background, so lot of things aren't exactly written as pure functions/methods).

neumann 2025-08-22T17:58:15.427259Z

On the main page of the podcast, @nate and I have table of contents of all the episodes organized by series: https://clojuredesign.club/ For workflow, check out: • Read, Eval, Print, Loop, Smile • Cooking Up Composition

✅ 1
2025-08-22T19:25:24.002139Z

Thanks a lot! @neumann

2025-08-22T19:32:11.892129Z

By the way, awesome work @neumann

neumann 2025-08-22T19:54:39.260009Z

@petrisrf Thank you!

Larry Jones 2025-08-21T17:55:37.242349Z

Robert Martin’s book, “Functional Programming,” takes a test first approach to most of his examples. It’s not a book on testing per se, but it might provide some ideas. Great aspirations. Hope you find good resources.

1
gaverhae 2025-08-24T08:43:04.682389Z

@petrisrf Assuming you use a Ring server, you're already mostly there: a Ring handler is a pure function from Ring request to Ring response. But then sometimes you have a database and things get messy, I guess. Another option is to go the integration testing route: it's pretty easy in your tests to just spin up your entire app as a web server on a random port and test it through its API, if appropriate. It's reasonably fast, too, in many cases.