You need to sign in to do that
Don't have an account?

Test coverage for url in Pagereference method with if statement
Hi everyone!
I am trying to test this code to obtain 100% coverage, but i can't figure out the problem. When i test it, I don't get an error but the code is still not 100%, kindly seeking your help, Thank you!
Code:
public Pagereference newPage() {
Id cohortRecordTypeId = Schema.SObjectType.class__c.getRecordTypeInfosByName().get('Cohort').getRecordTypeId();
String url = 'https://bitwisecommunity.force.com/instructorportal/CohortianRoster?id=' + classId;
if(classType == cohortRecordTypeId) {
url += '&type=Cohort';
}
return new PageReference(url);
}
Test Class:
static testMethod void testPagereference(){
class__c newClass = new class__c(name = 'Test Class', class_nights__c = 'Monday / Wednesday', start_date__c = date.today() - 10, end_date__c = date.today() + 45);
insert newClass;
Test.startTest();
// String cohRecordType = Schema.SObjectType.class__c.getRecordTypeInfosByName().get('Cohort').getRecordTypeId();
PageReference pref = Page.CohortianSelector;
Test.setCurrentPage(pref);
pref.getParameters().put('id',newClass.Id);
ApexPages.StandardController sc = new ApexPages.StandardController(newClass);
CohortianSelectorController myPage = new CohortianSelectorController(sc);
myPage.newPage();
Test.stopTest();
}
1. Insert the class__c record in Test class with record type:
2. or classType is local property not set by the class__c record in controller. then you can set the value from test class directly like below.
Thanks,
Maharajan.C
All Answers
1. Insert the class__c record in Test class with record type:
2. or classType is local property not set by the class__c record in controller. then you can set the value from test class directly like below.
Thanks,
Maharajan.C