How should I test boolean function with many possible permutationsa) this is an example; not real case; but often boolean expression are quite complex, even when reduced with intermediate steps: it' a bit like regular expression. b) I'm concerned when the test is more verbose and more complicated than the tested code: first it is a nightmare to maintain, and where are the tests for the tests then ?

How should I test boolean function with many possible permutationsYes, refactoring is the natural way to go. By the way my example was awful on purpose: it's the kind of code I'll found in my 'back to future' project. But sometime the expression is not so simple to decompose, or it belongs in external codebase that is not tested... Another point is that intermediate methods should be private, hence they should no be unit tested; and the permutation issue would stay the same. I would also prefer to have intermediate variables than intermediate methods for small bit like this, especially if the class contains already many methods.

Jun27

comment

How should I test boolean function with many possible permutationsI started to consider this option after having some trouble to write tests for heavy boolean expression. I considered the refactoring approach as suggested by MainMa, but then I considered truth tables (and generator for the parameter combinations). I asked the question here because I wanted to have hints from others before going to deep in this solution.