-4

Please help me to write Test class for my below Vf page and controller

The vf page

<apex:page standardController="Case" extensions="CaseDefault" action="{!Redirect}">

The Controller:-

 public class CaseDefault{

    public CaseDefault(ApexPages.StandardController controller){}

public pagereference Redirect()
    {
        PageReference pageRef;
        //To get the logged in userId and line of business value
        User u = [select Id, username, Line_of_Business__c from User where Id = :UserInfo.getUserId()];
            //case
     Map<String,String> parMap = Apexpages.currentPage().getparameters();
        //  System.debug('parMap'+parMap);
        String id= parMap.get('RecordType');
        System.debug('id of '+id);
       //if case record type is technical support
        if(id == '012b0000000DpIR' && u.Line_of_Business__c == 'Higher Ed'){
            pageRef = new PageReference('/500/e?retURL=%2F500%2Fo&RecordType=012b0000000DpIR&ent=Case&00Nb000000AGUYm=Higher%20Education&nooverride=1');
            }
        else if(id =='012b0000000DpIR' && u.Line_of_Business__c=='Professional'){
            pageRef = new PageReference('/500/e?retURL=%2F500%2Fo&RecordType=012b0000000DpIR&ent=Case&00Nb000000AGUYm=Professional&nooverride=1');

        }
       else {pageRef = new PageReference('/500/e?retURL=%2F500%2Fo&RecordType=012b0000000DpIR&ent=Case&nooveride=1');}
     pageRef.setRedirect(True);
        return pageRef;


    }
}

Below is my Test class; but i am still getting only 0% coverage plaese help what am i doing wrong here

 @istest
public class CaseDefaultTest {

testmethod private static void defaultcase(){
    PageReference pageRef;
 LIST<User> userlist=new LIST<User>();
    String caseRecordtypeid = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Technical Support').getRecordTypeId();
    userlist=TestDataFactory.createUser('00eb0000000RKQS');
    insert userlist;
    if(userlist[0].Line_of_Business__c == 'Higher Ed' && CaseRecordtypeid == 'Technical support'){
        pageRef = new PageReference('/500/e?retURL=%2F500%2Fo&RecordType=012b0000000DpIR&ent=Case&00Nb000000AGUYm=Higher%20Education&nooverride=1');

    }
}
}
1
  • 3
    Go through this trailhead and try it. If you get stuck then post it here. Commented Apr 5, 2017 at 10:12

1 Answer 1

2

From the code you provided there are two issues that I see:

  1. You don't call the class/method you are trying to test in your test method
  2. You don't set up any test data in your test method
  3. I would also not rely on using hard coded Ids in your code

You need to either add a setup method in your test method or add the (SeeAllData=true) annotation to your test method.

Not the answer you're looking for? Browse other questions tagged .