You need to sign in to do that
Don't have an account?
sieb4me
test class for this code
What would be test class for this code? Can anyone please suggest something.
Thanks.
global class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {
global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){
Case c = [SELECT Priority, Priority_On_Complete__c FROM Case WHERE Id=:caseId];
if (c.Priority_On_Complete__c == null) {
if (c.Priority != null && c.Priority.equals('P1'))
return 3;
else
if (c.Priority != null && c.Priority.equals('P2'))
return 6;
else
if (c.Priority != null && c.Priority.equals('P3'))
return 9;
else return 0;
}
else {
if (c.Priority_On_Complete__c.equals('P1'))
return 3;
else
if (c.Priority_On_Complete__c.equals('P2'))
return 6;
else
if (c.Priority_On_Complete__c.equals('P3'))
return 9;
else return 0;
}
}
}
Thanks.
global class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {
global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){
Case c = [SELECT Priority, Priority_On_Complete__c FROM Case WHERE Id=:caseId];
if (c.Priority_On_Complete__c == null) {
if (c.Priority != null && c.Priority.equals('P1'))
return 3;
else
if (c.Priority != null && c.Priority.equals('P2'))
return 6;
else
if (c.Priority != null && c.Priority.equals('P3'))
return 9;
else return 0;
}
else {
if (c.Priority_On_Complete__c.equals('P1'))
return 3;
else
if (c.Priority_On_Complete__c.equals('P2'))
return 6;
else
if (c.Priority_On_Complete__c.equals('P3'))
return 9;
else return 0;
}
}
}
Here are the guidelines to write the Test classs for above mentioned Class:
1. Create a sample Case record in test class and insert it.
2. write a SOQL query to fetch the same record.
3. Update the value of c.Priority_On_Complete__c & c.Priority field to NULL, P1, P2 ,P3 so thatit will cover both you IF & ELSE statements.
This will help you to achieve desired code coverage for the test class.
Thanks,
Pratik
P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
All Answers
Here are the guidelines to write the Test classs for above mentioned Class:
1. Create a sample Case record in test class and insert it.
2. write a SOQL query to fetch the same record.
3. Update the value of c.Priority_On_Complete__c & c.Priority field to NULL, P1, P2 ,P3 so thatit will cover both you IF & ELSE statements.
This will help you to achieve desired code coverage for the test class.
Thanks,
Pratik
P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.