dimanche 4 juin 2017

How to test a function with MxN paths?

I have a function which validates a model class where it has to check every member of the class to be non-null or non-empty in case of a String.

The logic for this is_complete function is something like this:

def is_complete(profile):
    if profile.first_name in (None, ''):
        return False
    elif profile.last_name in (None, ''):
        return False
    elif profile.dob is None:
        return False
    .
    .
    .# and checks so on for all members of the profile instance
    .
    .

    return True

My question since the number of possible paths the execution can take is quite large and increases in proportion to the number of member variables of profile to be checked, how does one reliably write tests for all the possible paths?

Right now, I have two simple test cases:

  1. where only some of the members are set and checks assertFalse(is_complete(foo))
  2. where all the members are set and checks assertTrue(is_complete(foo))

But I have a feeling that this may not be enough.

Aucun commentaire:

Enregistrer un commentaire