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
NatrajNatraj 

Is there any special way to cover the Class Catch Exception in test coverage...

Hi,

 

In some of the classes the (exceptions) Catch part are covered in test coverage and in some cases its not covering the catch exception in test code. Is there any special way to cover the catch part in test code..

 

Thanks in advance...

 

Natraj..

Ankit AroraAnkit Arora

Nothing much to worry. Catch code is simple code which we can cover as we do for our normal code. For example I have written a code in which I am passing an integer value which is used to do some calculation. In try part I have written the logic and in catch part I have written system debug.

 

Now your test cases should cover two scenarios, first will contain the valid value which will cover try part and other will have invalid value which will generate error in my calculation that will cover my catch part.

 

Hope it will help

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Muruganand_SforceMuruganand_Sforce

Hi Ankit,

 

In this case,What will happen when you set string value and the compiler itself throw a error meaning catch block will not cover.

 

Muruganand