+ Start a Discussion

how to cover the test class for apexpages.addmessage that Doesn't include any dml exceptions but it has the custom validation rules throwing the errors


I have written a test class that covers 86% leaving out the apexpages.addmessage () in catch block, but majorly it throws the validation exceptions on that object when I try to update a record.(Here I am updating case status to closed and I have some custom fields to be filled out while closing the case).

My test class has 2 methods. 1st method is having the case with all the fields filled this covers all the code except catch block and 2nd method without the required fields while closing the case and even though it doesn't cover my test class to full 100% 

Can someone please provide any suggestions .

deepak balur 19deepak balur 19
Vamsi, In your actual class you need to put in something arbitrary like insert Contact after checking for IsTestRunning.... what will happen is it will intentionally fail and then your execptions i.e. the Add Messages will be covered.