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
pranav anandpranav anand 

create test class of following code

public class PricebookEntryDetailController
{
    public PageReference products()
    {
        return null;
    }
    public Set<String> selectedRecordIds{get;set;}//Set for maintaining which Id's are selected
    public integer index = 0;
    public integer blockSize = 5; 
    public List<PBEwrapper> wrapperList{get;set;}
    public List<SelectOption> pricebookList;
    public String selectedPriceBookId{get;set;}
    public List<pricebookEntry> priceDetailList{get;set;}
    public Map<Id,PricebookEntry> cartItemsMap {get;set;}
   
    //constructor
    public PricebookEntryDetailController()
    {   
        selectedRecordIds = new Set<String>();
        wrapperList = new List<PBEwrapper>(); 
        priceDetailList = new List<pricebookEntry>();
       
    }
   
   
    // Get Availabel Price Books
    public List<SelectOption> getPricebookList()
    {
        pricebookList = new List<SelectOption>();
       
        for(Pricebook2 pb:[select id, name from pricebook2])
        {
            pricebookList.add(new selectoption(pb.id,pb.name));
        }
        return pricebookList;
    }

   
    // Product List 
    public List<PBEwrapper> getProducts()
    {
        wrapperList.clear();
        priceDetailList.clear();
       
        priceDetailList = Database.Query('SELECT Id,Product2.Name,Product2.productcode, UnitPrice FROM PricebookEntry where Pricebook2Id=: selectedPriceBookId limit :blockSize offset :index');
       
        //Product check list
        for(pricebookEntry entry : priceDetailList )
        {
             if( selectedRecordIds.contains(entry.Id))
                 wrapperList.add(new PBEwrapper(entry,true));
             else
                 wrapperList.add(new PBEwrapper(entry,false));
        }
       
        return wrapperList;
    }
   
   
    //to get page Number
    Public Integer PageNumber
    {
        get{return index/blockSize+1;}
        set;
    }

    // Go to next page of product list
    public void next()
    {
        //loop for maintaining which Id's are selected
        for(PBEwrapper p : wrapperList)
        {
            if (p.selected && !selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.add(p.PriceEntry.Id); 
            else if(!p.selected && selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.remove(p.PriceEntry.Id);
        }
       
        index += blockSize;
    }
   
    // Go to previous page of product list
    public void previous()
    {
        //loop for maintaining which Id's are selected
        for(PBEwrapper p : wrapperList)
        {
            if(p.selected && !selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.add(p.PriceEntry.Id);
            else if(!p.selected && selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.remove(p.PriceEntry.Id);
        }
       
        index -= blockSize; 
    }
   
   
    // Total No. of products in pricebook
    public Integer totalRecs
    {
        get
        {
            totalRecs = 0;
            if(selectedPriceBookId!= Null || selectedPriceBookId != '')
                totalRecs = [select count() from pricebookEntry where Pricebook2Id=: selectedPriceBookId];
           
            return totalRecs;
        }
        set;
    }
   
    // To Make next button disbled if there is no next page
    public Boolean gethasNext()
    {
        if((index + blockSize) >= (totalRecs-index))
            return true;
        else
            return false;
    }
   
    //To Make pevious button disbled if there is no previous page
    public Boolean gethasPrevious()
    {
        if(index == 0)
            return true;
        else
            return false;
    }
   
   
    //Redirect to cart page
    public PageReference AddToCart()
    {
        for(PBEwrapper p : wrapperList)
        {
            if(p.selected && !selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.add(p.PriceEntry.Id);
            else if(!p.selected && selectedRecordIds.contains(p.PriceEntry.Id))
                selectedRecordIds.remove(p.PriceEntry.Id);
        }
        cartItemsMap = new Map<Id,PricebookEntry>([SELECT Id,Product2.Name,Product2.productcode, UnitPrice FROM PricebookEntry where Id IN: selectedRecordIds]);
        PageReference cartPage = Page.PricebookEntryDetails2;//here is new VF page Redirect through (Add To Cart) Button
        cartPage.setRedirect(false);
        return cartPage;
    }
 
    //To delete the selected records
    public void DeletingRow( )
    {
        String cartItemId =  Apexpages.currentPage().getParameters().get('recordId');
        cartItemsMap.remove(cartItemId);
    }
   
    // Redirect to main page
    public PageReference BackToMainPage()
    {
        PageReference mainpage = Page.PricebookEntryDetails;//here is the main VF page redirect through Button
        mainpage.setRedirect(false);
        return mainpage;
    }
   
    //wrapper class
    class PBEwrapper
    {
        public PricebookEntry PriceEntry{get;set;}
        public Boolean selected{get;set;}
        public PBEwrapper(PricebookEntry pbe,Boolean selected)
        {
            PriceEntry = pbe;
            this.selected = selected;
        }
    }
}
bob_buzzardbob_buzzard
Is this a class that you have written?  If so, how is it that you are able to write the controller code but not any test class code and, more to the point, why you think it is the job of the community - people who give up their time for free - to write this for you?  I'm genuinely interested here - every day we see post after post of sometimes complex Apex code, but with no attempt at writing the test class - why is this?