Testing both ways

I have just been taught the lesson that when testing your code, test for failures too.

Take a method that removes a record from the database. You pass in the Id of the record and it DELETEs it. Initially I tested for an invalid Id (e.g. -1) and for a successful delete. I never tested to see what happens when you pass in a valid Id but an Id that doesn’t occur in the database. In this case the code ran as if it were successful. Really it should throw an exception as that Id does not exist in the database.

Test both ways!

Viewing 2 Comments

 

Trackbacks

(Trackback URL)

close Reblog this comment
blog comments powered by Disqus