+ Start a Discussion
Waqar Hussain SFWaqar Hussain SF 

How to write test class for my accountPagination class.

public with sharing class AccountPagination {
    private final Account acct;  

    // The constructor passes in the standard controller defined
    // in the markup below
            public AccountPagination(ApexPages.StandardSetController controller) {
        this.acct = (Account)controller.getRecord(); 
    public ApexPages.StandardSetController accountRecords {
        get {
            if(accountRecords == null) {
                accountRecords = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Name FROM Account WHERE Id NOT IN 
                        (SELECT AccountId FROM Opportunity WHERE IsClosed = true)]));
            return accountRecords;
        private set;
    public List<Account> getAccountPagination() {
         return (List<Account>) accountRecords.getRecords();
Best Answer chosen by Waqar Hussain SF
rajesh k 10rajesh k 10
              Find below code 100% code coverage

public class TestAccountPagination {
    public static testmethod void unittest()
        List<Account> acclist=new List<Account>();
        for(Integer i=1;i<15;i++)
            Account acc=new Account();
            acc.Name='My account';
            //add mandatory fields
        insert acclist;
        ApexPages.StandardSetController sc = new ApexPages.StandardSetController(acclist);

        AccountPagination scExt = new AccountPagination(sc);


this is currect make it as best answer....