Unit test thoroughness - test passing conditions as well as failing ones? -


should unit tests test passing conditions failing conditions?

for example, imagine have test widget_cannotactivewidgetifstateiscancelled.

and let's there 100 possible states.

can away testing cannot activate widget when state == cancelled, or have test can activate in each of other 99 states?

is there compromise can let me avoid spending time writing tests? :)

it seems asking whether tests should exhaustive: whether should test possible states. answer resounding no, simple reason simple code can have far many states. small programs can have more potential states can tested if used time there has been since big bang.

you should instead use equivalence partitioning: identify groups of states, such states in group have similar behaviour, have 1 test case per group.

if that, might discover need 2 test cases.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -