Functional Programming

Functional Programming And Testing

I was thinking about testing something that’s written using functional programming. The implications to Software Testing because of it are interesting.

No Loops, No branching

When there are no loops, and there is no branching, most of the combinations are taken away, and much of the testing effort is also taken away. The program will flow as one straight piece, and mostly what needs to be verified would be the outputs, given the inputs.

No Global variables, No State

As there would be no global variables, and hence there would be no state for the program, the testing associated with global variables and the state of the program are taken off.

Order of execution of functions does not matter

The order in which functions in a module are executed does not matter, so they can be executed in any sequence or in parallel. Here I can see testing to make sure that the order of execution does not indeed matter (by verifying that the end result is always the same irrespective of the order in which the functions are executed. Testing is also needed to make sure that the end results are achieved even if the functions are executed in parallel, oftentimes following different order of execution.

One major consideration is that the testing should verify that the transformation from input to the output happens correctly. There are several advantages that are said about FP (Functional Programming), and testing can verify that those advantages are really true and working as expected.

In summary, testing in a FP space is a totally different game, and the test strategy will be pretty interesting. Mind trying FP? Try programming languages that support FP.

I’ll try to write in detail about the various aspects involved in testing of software written with FP.

Happy Testing, and feel free to contact me.

Leave a Comment

Your email address will not be published. Required fields are marked *