+ Start a Discussion

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.

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.