In first testmethod if yout “IF” condition matches criteria then it would be execute. For covering “else” condition you should write another testmethod in which the situtation should not satisfy “if” criteria hence automatically “Else” part would be executed. Thank You
What are the best practices for unit testing in Salesforce?
One of the other things that Salesforce recommends for unit testing is to put your test setup into a single method using the @testSetup annotation.
Does if (condition) block cover else condition in Test class?
ELSE condition in test class I tried this test class, but it only covers else part. it does not cover if (condition) block. Help me to achieve 100% code coverage. Thank-You! Please check once above code also. Thank you for the quick reply! but both the code is not working, I mean still IF block is not cover. Thank-You!
How to handle if/else condition in a test method?
For covering “else” condition you should write another testmethod in which the situtation should not satisfy “if” criteria hence automatically “Else” part would be executed. Yes if there is “else if” ladder then for each “else if” condition you hould specify different test class else your code will not be covered hundred percent.
Can I Share my test case with TestClass?
If you can share your class and testClass , it will be helpful to suggest you test case. You need to sign in to do that. Need an account? Sign Up Have an account?