Timeline for Skipping exception code in test class
Current License: CC BY-SA 4.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 1, 2022 at 0:58 | vote | accept | Balaji Pooruli | ||
Nov 29, 2022 at 16:27 | answer | added | sfdcfox♦ | timeline score: 1 | |
Nov 29, 2022 at 16:27 | comment | added | Phil W |
You have misunderstood Test.isRunningTest . It does not delimit lines that should not be considered part of test coverage, but instead allows you to avoid executing certain lines of code during execution of a test. I recommend against such approaches in general since it means you are not actually fully testing your production code and have different behaviour under test. This is bad practice. Only use this if absolutely essential (e.g. if you haven't structured your code to allow dependency injection and you need to avoid sending an email).
|
|
Nov 29, 2022 at 16:14 | history | edited | Derek F |
edited tags
|
|
Nov 29, 2022 at 16:14 | comment | added | Derek F |
Instead of trying to cover the catch block, you should probably just remove the try/catch altogether. The only exceptions you could run into here are limit exceptions (which are uncatchable). You should also be using a trigger framework so you can keep your logic out of your trigger.
|
|
Nov 29, 2022 at 16:10 | history | asked | Balaji Pooruli | CC BY-SA 4.0 |