You need to sign in to do that
Don't have an account?
wsmith
Do I have to explicitly create a object that will fail in the insert even though it has nothing to do with the logic I really want to test.
Does that mean I have to create up to 100 (more or less depending on the governor limit of the environment) test objects to get past the "if' statement and test the code in the block?
Code coverage best practice
How can I get code coverage in the follow DMLException?
Code:
try { insert oppList; } catch (DmlException e) { for (Integer i = 0, leni = e.getNumDml(); i < leni; ++i) { Opportunity o = oppList.get(e.getDmlIndex(i)); o.addError(e.getDmlMessage(i)); } }
Do I have to explicitly create a object that will fail in the insert even though it has nothing to do with the logic I really want to test.
In another example; from the Cookbook, there is:
Code:
if ((updatedContacts.size() + Limits.getDMLRows()) > Limits.getLimitDMLRows()) { ... ... }
Does that mean I have to create up to 100 (more or less depending on the governor limit of the environment) test objects to get past the "if' statement and test the code in the block?
It seems that best practices does not allow code coverage for those areas; unless it is expected these areas will be a small amount of code in a class and it is ok not to test them?
SFHack
Are there any recommendations on this? I had to comment out some of my "shouldn't happen" error handling to get my code to deploy to production.