mercredi 18 février 2015

testing in functional programming

in object oriented programming i have objects and state. so i can mock all dependencies of an object and test the object. but functional programming (especially the pure) is about composing functions


it's easy to test function that doesn't depend on other functions. we just pass parameter and check the result. but what about function that takes another functions and returns functions?


let's say o is composition and i have the code g = h1 o h2 o h3 o h4. should i test just function g? but that's integration/functional testing. it's impossible to test all branches with only integration tests. what about unit testing? and it's getting more complicated when a function takes more parameters.


should i create custom functions and use them as mocks? wouldn't it be to expensive and error prone?


and what about monads? for example how to test console output or disk operations in haskell?


Aucun commentaire:

Enregistrer un commentaire