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
Pradeep Musthi 9Pradeep Musthi 9 

TEST CLASS FOR CUSTOM CONTROLLER WHICH RETRIVES ACCOUNT RECORDS WITH CHECKBOX

ListOfAccounts VfPage
<apex:page controller="Controller1" >
<apex:form >
<apex:PageBlock title="Account">
<apex:outputLabel value="Enter Account Name: ">
<apex:inputText value="{!AccountName}"/>
</apex:outputLabel>
<apex:commandButton value="Search" action="{!Display}"/>
    </apex:PageBlock>
<apex:pageBlock title="The list of account are" rendered="{!b2}">
<apex:outputText  value="{!Error}"></apex:outputText>    
</apex:pageBlock>
<apex:pageBlock title="The list of account are" rendered="{!b1}">   
<apex:pageBlockTable value="{!acclist}" var="b">
  
<apex:column headerValue="Action">
<apex:inputCheckbox value="{!b.Checked}"/>
</apex:column>
    <apex:column value="{!b.acc.Name}"/>

</apex:pageBlockTable>


 <apex:pageBlockButtons >
    <apex:commandbutton value="Get Details" action="{!Details}" />
        </apex:pageBlockButtons>
</apex:PageBlock>
</apex:form>
</apex:page>

SelectedAccounts VfPage
<apex:page controller="Controller1" >
<apex:pageBlock Title="Details of selected accounts are">
<apex:pageBlockTable value="{!Selected}" var="c">
    <apex:column value="{!c.id}" />
    <apex:column value="{!c.Name}"/>
    <apex:column value="{!c.type}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Controller1-->Custom Controller
public class Controller1 {
public string AccountName{Get;Set;}
public list<waccount> acclist{Get;Set;}
public list<Account> selected{Get;Set;}
public boolean b1{Get;Set;}
public boolean b2{Get;Set;}
public string Error{Get;Set;}
public void Display()
{
    if(acclist==null)
    {
        acclist=new list<waccount>();
        list<Account> ls=[select name,type from account where name=:AccountName];
        if(ls.size()>0)
        {
        b1=true;
        for(Account a:ls)
        {
            acclist.add(new waccount(a));
        }
        }
        else
        {
            b2=true;
            Error='No Account Found with that name';
        }
    }
}
public PageReference Details()
{
    selected=new List<Account>();
    for(waccount w:acclist)
    {
        if(w.checked==true)
        {
            selected.add(w.acc);
        }
    }
    return page.SelectedAccounts;
}
public class waccount
{
    public Account acc{get;set;}
    public boolean checked{get;set;}
    public waccount(Account acc)
    {
       this.acc=acc;
       checked=false;
    }
}
}

Can Anyone help me with test class for above controller 
PINKY REGHUPINKY REGHU
Hi, 
  Try this code
@isTest 
public class ControllerTestClass 
{
      static testMethod void withname() 
	 {
		Account testAccount = new Account();
		testAccount.Name='Test Account' ;
                insert testAccount;
                System.Test.StartTest(); 
               Controller1.waccount testWrap=new Controller1.waccount(testAccount);
               Controller1 testAccPlan = new Controller1();
                testAccPlan.Display();	
		testAccPlan.Details();	
		System.Test.StopTest();
           }
}
Please let me know if that helps you.
If it helps don't forget to mark this as a best answer!!!