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
MaddyConnectMaddyConnect 

How to cover code in Finally block using test class?

Hi Guys,

Does anyone know the way to cover cod in 'Fianlly' block using test class? Currently I am getting 70% coverage, however lines not covered are in 'Fianlly' block. To reach 75% I have to cover code in 'Fianlly' block.

Thanks,
Mahadev
Hargobind_SinghHargobind_Singh
Usually for catch-blocks, we sometimes generate an exception within the code, like a divide by zero exception and encapsulate it within a System.isTest method, so that it only runs if the test is running, and produces exception. This could also be dependent on a state variable so that you can check in normal conditions as well.