function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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!

Thanks.

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);
        ApexPages.addMessage(myMsg);
}
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