DISQUS

DISQUS Hello! Life is grand is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Testing both ways

Started by paulmwatson · 10 months ago

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 [. ... Continue reading »

2 comments

  • You make a good point but your example raises an interesting question.

    If you request deletion of ID n then the successful result is that the row with ID n no longer exists after the operation. This is the case if ID n did not exist in the first place so can it really be said to be an error if a non-existent item is deleted?
  • Good point Steve.

    I think though throwing an exception when no rows were affected gives better information to the caller than just silently continuining as if a row was affected. The caller can then choose what to do with that info.

Add New Comment

Returning? Login