Return to Snippet

Revision: 16625
at August 10, 2009 05:57 by Tierlieb


Initial Code
public void testShouldNotFindAfterDeletion(){
   manager.createContact(contact);
   manager.deleteContact(contact.getID());
   
   /* now try to read it again to make sure the delete request works: */
   
   try {
      manager.getContact(contact.getID()); //this throws an AssertionError.
      fail("Should not reach this step, should throw exception first"); //mistake that should have been obvious: This also does.
   } catch (AssertionError e){
      //succeed
   };
}

Initial URL

                                

Initial Description
I was refactoring code lately, changed a method to return null instead of throwing an error - yet this test kept working. I did not get why for quite some time.

Lesson learned: Never rely on Eclipse generating a try-catch-block without actually looking what kind of exception or error it catches.

Initial Title
Testing for an error using exception handling - the stupid way

Initial Tags

                                

Initial Language
Java