You need to sign in to do that
Don't have an account?
Sujit Karande
Check string value in test class
Below is the code for my test class.
And only first if condition is getting tested and other is skipping which is why the code is not reaching 75% off code coverage.
the field standard_or_nonstandard__c is picklist having two values Yes & No.
And if the value if Yes, the deal type should be standard, and if No, the deal type is not standard.
Any suggestion on this?
Opportunity opp = [select Deal_Type__c from opportunity where Id: = <some id>]; Case objCase = new Case(); objCase.standard_or_nonstandard__c = 'Yes'; if(objCase.standard_or_nonstandard__c = 'Yes'){ // this if is getting tested opp.Deal_Type__c = 'Standard'; } else{ // else part is getting skipped opp.Deal_Type__c = 'Not Standard'; }
And only first if condition is getting tested and other is skipping which is why the code is not reaching 75% off code coverage.
the field standard_or_nonstandard__c is picklist having two values Yes & No.
And if the value if Yes, the deal type should be standard, and if No, the deal type is not standard.
Any suggestion on this?
You should wirte both IF and ELSE condition in test like below sample:
In this case your both condition will run in test class. Hope this will help you.
Please let me know if it helped or you need any more assistance.
Please mark this is as the solution if it solved your purpose.
Thanks,
Sohan Raj Gupta
But unfortunately, it doesn't work.
Can you please try the below code and let me know if it helps you:
Opportunity opp = [select Deal_Type__c from opportunity where Id: = <some id>];
Case objCase = new Case();
Case objCase1 = new Case();
objCase.standard_or_nonstandard__c = 'Yes';
if(objCase.standard_or_nonstandard__c = 'Yes'){ // this if is getting tested
opp.Deal_Type__c = 'Standard';
}
else{ // else part is getting skipped
opp.Deal_Type__c = 'Not Standard';
}
objCase1.standard_or_nonstandard__c = 'No';
if(objCase1.standard_or_nonstandard__c = 'Yes'){ // this if is getting tested
opp.Deal_Type__c = 'Standard';
}
else{ // else part is getting skipped
opp.Deal_Type__c = 'Not Standard';
}
Please let me know if it works.
Thanks,
Jainam Contractor,
Salesforce Consultant,
Varasi LLC
www.varasi.com
It reduces the code coverage by 1%
Is the above code your test class or is it the actual class and you want a test class for the same.
Can you please share your test class and the actual class...
Thanks,
Jainam Contractor
The code in question is of the test class. Below is the code in actual class
You can insert some dummy records in Test Class and then call those same records in the Class Method.
Assume Class Name : CaseOpp
Method Name : FetchCase
Below would be the Test Class:
Please check and let me know if it works.
Thanks,
Jainam Contractor