r/functionalprogramming • u/Mishkun • Sep 28 '24
Question Any books on unit testing FP code?
OOP folks have a lot of book about unit testing code, movks/stubs debate and other things. Is there anything for the FP?
15
Upvotes
6
u/jhartikainen Sep 28 '24
Correct me if I'm wrong, but isn't it more or less the same in both cases? Same principles apply regardless of paradigm.
3
u/graninas Oct 01 '24
My book Functional Design and Architecture contains a whole chapter on testing, including unit testing. It discusses pros and cons of various approaches and shapes a methodology of making testable functional architectures. Besides, it proposes an automatic white-box testing approach that can be achieved with free monads and can be used for golden tests. It discusses the pros and cons of various approaches and shapes a methodology for making testable functional architectures because enrolling a sane testing strategy without having a good architecture is barely possible.
15 Testing
15.1 Testing in functional programming
15.1.1 Testing basics
15.1.2 Property-based testing
15.1.3 Property-based testing of a Free monadic scenario
15.1.4 Integration testing
15.1.5 Acceptance testing
15.2 Advanced testing techniques
15.2.1 Testable architecture
15.2.2 Mocking with Free monads
15.2.3 White-box unit testing
15.2.4 Testing framework
15.2.5 Testability of different approaches
15.3 Summary
https://www.manning.com/books/functional-design-and-architecture
There is a post about white-box testing, btw:
https://github.com/graninas/automatic-whitebox-testing-showcase
21
u/josh_in_boston Sep 28 '24
In my experience, unit testing FP code is so much easier, a book is hardly needed.
7
u/mbuhot Sep 28 '24
testing elixir and property based testing with proper may be of interest.
4
u/recursion_is_love Sep 29 '24
There is a tutorial paper for using QuickCheck with Erlang
https://www.researchgate.net/publication/225219256_Software_Testing_with_QuickCheck
3
u/TheTravelingSalesGuy Sep 29 '24
This is just an article but I think that you might find it interesting. property based testing
FP work very well with property based testing. Maybe you have a parser and a pretty printer and you want to make sure that they both stay up to date with each other. So you just write a test like "parse . prettyPrint === id".
2
u/bilus Sep 29 '24
This is fantastic: https://fsharpforfunandprofit.com/series/property-based-testing/ F# but completely transferrable to other languages.
2
u/snarkuzoid Sep 30 '24
Testing? Isn't that what users are for?