jeudi 23 avril 2015

How do I do basis path coverage testing with a return statement?

What are the tests sets for the following code to do basis path coverage?

/**
 * Attempt to rename a tag. newName must not be null.
 * Returns true/false
*/
public boolean renameTag(String oldName, String newName) { 
if(oldName.equals(newName))
       return false;

Tag tag = tags.get(oldName);
if(tag == null)
       return false;

if(tags.containsKey(newName))
       return false;

tags.remove(oldName);
tag.setName(newName);
tags.put(newName, tag);
return true;
}

From my understanding basis path coverage should be:

TTT
FTT
TFT
TTF

But that does not work in this example because of the returns after the conditional is true. My tests will only test the first and second conditional and the 3rd conditional will never be testes.

Aucun commentaire:

Enregistrer un commentaire