+ Start a Discussion
Romeo MirzacRomeo Mirzac 

Apex Unit Testing Problem

After adding error checking to my Apex classes (try..catch blocks), my apex unit tests are now less than 100%.  Apparently I'm not testing for the Catch part of my code.  I can't for the life of me figure out how to test for this.  Help!


My catch blocks are all like this:

Catch (Exception ex) {
     String strMsg = 'An error occurred: ' + ex;
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, strMsg);
Best Answer chosen by Romeo Mirzac
Michael VerhovskiMichael Verhovski
There are several good examples of exception testing in How to Write Good Unit Tests (https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests) article