function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul Gupta 176Rahul Gupta 176 

need help in test class for controller

public class AccListCon 
 {
    public List<Account> listAccount { get; set; }
    public integer blockSize;
    public integer offSetVar;
    public integer total_size;
    
    public AccListCon()
      {    
        offSetVar =0;
        blockSize =10;
        listAccount = [Select id, Name,BillingCity,Custom_Emaail__c ,OwnerId,phone from Account limit:blockSize  ];
        total_size=[select count() from account];
        //isbtnEnable = true;
     }
     
     public PageReference funPagination()
     {
        listAccount = [Select id, Name,BillingCity,Custom_Emaail__c ,OwnerId,phone from Account limit:blockSize offset:offSetVar ];
        return null;
    }
    
    
    public PageReference goToFirst() 
    {
        funPagination();
        offSetVar=0;
        return null;
    }
    
    
    
    public PageReference goToPrev() 
    {
        funPagination();
        if(offSetVar>0)
        {
        offSetVar=offSetVar-blockSize;
        }
        else 
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'This is last page of list '));
         return null;
    }
    
    public PageReference goToNext() 
    {
        funPagination();
        offSetVar=offSetVar+ blockSize; 
        isbtnEnable = true;     
        return null; 
        
    }   
    public PageReference goToLast() 
    {
       funPagination();
        if (offSetVar + blockSize < total_size) 
        {
        offSetVar = total_size - math.mod(total_size, blockSize);
        }
        else 
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'This is last page of list '));
       return null;
    }
}
-------------------------------------------------------------------------------------------
<apex:page controller="AccListCon">
 <apex:form >
      <apex:pageBlock >
      <apex:pageMessages ></apex:pageMessages>

    <apex:pageblockSection >
        <apex:pageBlockTable id="tblId" value="{!listAccount}" var="acc">
        <apex:column value="{!acc.id}"/>
            <apex:column value="{!acc.name}"/>
        
        </apex:pageBlockTable>
       
      </apex:pageblockSection>
       <apex:pageblockButtons >
         <apex:commandButton action="{!goToFirst}" reRender="tblId" disabled="{!isbtnEnable}" value="<<"/>
         <apex:outputPanel id="btnPanelId">
            <apex:commandButton id="btn1" action="{!goToPrev}" reRender="tblId,btnPanelId" value="<"/>
            <apex:commandButton action="{!goToNext}" reRender="tblId,btnPanelId,btn1" value=">"/>
            <apex:commandButton action="{!goToLast}" reRender="tblId,btnPanelId" value=">>"/>
            </apex:outputPanel>
        </apex:pageblockButtons>
      </apex:pageBlock> 
    </apex:form>
</apex:page>

So please help me with the test class i am unable to write 
Banwari kevat1Banwari kevat1
Hi Rahul,
Please run the following test class and check you code coverage.
@isTest
private class AccListConTest{
    @testSetup
    static void setupData(){
        insert new List<Account>{
            new Account(Name='test1',BillingCity='test billing city1'),
                new Account(Name='test2',BillingCity='test billing city2'),
                new Account(Name='test3',BillingCity='test billing city3'),
                new Account(Name='test4',BillingCity='test billing city4'),
                new Account(Name='test5',BillingCity='test billing city5'),
                new Account(Name='test6',BillingCity='test billing city13'),
                new Account(Name='test7',BillingCity='test billing city23'),
                new Account(Name='test8',BillingCity='test billing city33'),
                new Account(Name='test9',BillingCity='test billing city43'),
                new Account(Name='test10',BillingCity='test billing city53'),
                new Account(Name='test11',BillingCity='test billing city63'),
                new Account(Name='test12',BillingCity='test billing city73'),
                new Account(Name='test31',BillingCity='test billing city38')

                };
                    }
    
    static testmethod void testmethod1(){
        AccLIstCon accListConObj = new AccLIstCon();
        accListConObj.goToLast();
        accListConObj.goToFirst();
        accListConObj.goToNext();
        accListConObj.goToPrev();
        accListConObj.goToNext();
        accListConObj.goToLast();
        accListConObj.goToLast();
        accListConObj.goToNext();
        accListConObj.goToLast();
        
        
    }
    
}

Thanks
Banwari