• Logu
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi All,
 Can any one help me to increase my test class code coverage to 100%, This is my first test class, Now my test class coverage is 87%, I want to increase the code coverage to 100%, What are the changes i need to do in my test class to get code coverage of 100%?

Thanks in advance.

my controller class
================
public with sharing class AccountListViewTaskCon {
     public Id accountId                                {    get; set;    }
     public Boolean pbTablebool                         {    get; set;    } // boolean value to render pageblocktable
     public String SearchAccName                        {    get; set;    }
     public String queryString                          {    get; set;    }
     List <Account> accounts;
     public Apexpages.StandardSetController controller    {get; set;}
    
     public AccountListViewTaskCon()
     {
        controller    = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name,Industry,Rating,Account_Priority__c,Owner.Name,Account_Region__c FROM Account]));
        controller.setPageSize(20);
        pbTablebool  = True;           
     }
    public List<Account> getAccounts()
    {
        return (List<Account>) controller.getRecords();
    }
    public void doDelete()
    {
       try
        {
            delete [select Id from Account where Id =: accountId];
        }
        catch(Exception e)
        {
               ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
        }//try
    }
    public void doSearch()
    {
        try{
            //null or empty check
            System.debug('SearchAccName : '+SearchAccName);
            queryString = 'select id,Name,Industry,Rating,Account_Priority__c,Owner.Name,Account_Region__c from Account  where Name Like \''+SearchAccName+'%\' ';
            controller    = new ApexPages.StandardSetController(Database.Query(queryString ));
          }
        catch(System.QueryException qe)// exception handling
        {
          ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.error, qe.getMessage());
          ApexPages.addMessage(msg);
        }
    }
    // indicates whether there are more records after the current page set.
    public Boolean hasNext
    {
        get {
            return controller.getHasNext();
        }
        set;
    }

    // indicates whether there are more records before the current page set.
    public Boolean hasPrevious {
        get {
            return controller.getHasPrevious();
        }
        set;
    }
    // returns the page number of the current page set
    public Integer pageNumber {
        get {
            return controller.getPageNumber();
        }
        set;
    }
    // returns the first page of records
     public void first() {
         controller.first();
     }

     // returns the last page of records
     public void last() {
         controller.last();
     }

     // returns the previous page of records
     public void previous() {
         controller.previous();
     }

     // returns the next page of records
     public void next() {
         controller.next();
     }

     // returns the PageReference of the original page, if known, or the home page.
     public void cancel() {
         controller.cancel();
     }
}

My test class
==========

@isTest(SeeAllData=true)

public class TestAccountListViewTaskCon
{
        public static boolean returnValueBooleanhasNext ;
        
        public static boolean returnValueBooleanhasPrevious  ;
        public static integer pageNumber ;
       
        public static  AccountListViewTaskCon objAccountListViewTaskConPageCon ; 
        static testMethod void runPositiveTestCases() 
        {
             objAccountListViewTaskConPageCon =  new AccountListViewTaskCon(); 
            system.Test.startTest();
            objAccountListViewTaskConPageCon.getAccounts();
            objAccountListViewTaskConPageCon.doDelete();
            objAccountListViewTaskConPageCon.doSearch();
            objAccountListViewTaskConPageCon.first();
            objAccountListViewTaskConPageCon.last();
            objAccountListViewTaskConPageCon.previous();
            objAccountListViewTaskConPageCon.next();
            objAccountListViewTaskConPageCon.cancel();
            returnValueBooleanhasNext  = objAccountListViewTaskConPageCon.hasNext;
            returnValueBooleanhasPrevious  = objAccountListViewTaskConPageCon.hasPrevious; 
             pageNumber =  objAccountListViewTaskConPageCon.pageNumber ;
            System.assertEquals(false, returnValueBooleanhasNext  );
            System.assertEquals(false, returnValueBooleanhasPrevious  );
System.assertEquals(1, pageNumber );
system.Test.stopTest();

        }
      
}
  • March 11, 2015
  • Like
  • 0
HI,
 I am new to salesforce, Can any one help me to fix this issue. I am trying to write test class for updating the record using standard controller, and extension .I am getting exception in objAccount , which throws System.QueryException: List has no rows for assignment to SObject.

      I can get the results in query editor by executing 'select name, owner.name, site ,id, Industry from account where id = '0019000001FYa8GAAT' ' this query ,
       
Account objAccount = [select name, owner.name, site ,id, Industry from account where id = '0019000001FYa8GAAT' ];
ApexPages.StandardController sc = new ApexPages.standardController(objAccount);
myPageCon = new AccountEditPageCon(sc);

Please help me to fix this issue. Thanks in advance
 
  • March 09, 2015
  • Like
  • 0
Hi All,
 Can any one help me to increase my test class code coverage to 100%, This is my first test class, Now my test class coverage is 87%, I want to increase the code coverage to 100%, What are the changes i need to do in my test class to get code coverage of 100%?

Thanks in advance.

my controller class
================
public with sharing class AccountListViewTaskCon {
     public Id accountId                                {    get; set;    }
     public Boolean pbTablebool                         {    get; set;    } // boolean value to render pageblocktable
     public String SearchAccName                        {    get; set;    }
     public String queryString                          {    get; set;    }
     List <Account> accounts;
     public Apexpages.StandardSetController controller    {get; set;}
    
     public AccountListViewTaskCon()
     {
        controller    = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name,Industry,Rating,Account_Priority__c,Owner.Name,Account_Region__c FROM Account]));
        controller.setPageSize(20);
        pbTablebool  = True;           
     }
    public List<Account> getAccounts()
    {
        return (List<Account>) controller.getRecords();
    }
    public void doDelete()
    {
       try
        {
            delete [select Id from Account where Id =: accountId];
        }
        catch(Exception e)
        {
               ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
        }//try
    }
    public void doSearch()
    {
        try{
            //null or empty check
            System.debug('SearchAccName : '+SearchAccName);
            queryString = 'select id,Name,Industry,Rating,Account_Priority__c,Owner.Name,Account_Region__c from Account  where Name Like \''+SearchAccName+'%\' ';
            controller    = new ApexPages.StandardSetController(Database.Query(queryString ));
          }
        catch(System.QueryException qe)// exception handling
        {
          ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.error, qe.getMessage());
          ApexPages.addMessage(msg);
        }
    }
    // indicates whether there are more records after the current page set.
    public Boolean hasNext
    {
        get {
            return controller.getHasNext();
        }
        set;
    }

    // indicates whether there are more records before the current page set.
    public Boolean hasPrevious {
        get {
            return controller.getHasPrevious();
        }
        set;
    }
    // returns the page number of the current page set
    public Integer pageNumber {
        get {
            return controller.getPageNumber();
        }
        set;
    }
    // returns the first page of records
     public void first() {
         controller.first();
     }

     // returns the last page of records
     public void last() {
         controller.last();
     }

     // returns the previous page of records
     public void previous() {
         controller.previous();
     }

     // returns the next page of records
     public void next() {
         controller.next();
     }

     // returns the PageReference of the original page, if known, or the home page.
     public void cancel() {
         controller.cancel();
     }
}

My test class
==========

@isTest(SeeAllData=true)

public class TestAccountListViewTaskCon
{
        public static boolean returnValueBooleanhasNext ;
        
        public static boolean returnValueBooleanhasPrevious  ;
        public static integer pageNumber ;
       
        public static  AccountListViewTaskCon objAccountListViewTaskConPageCon ; 
        static testMethod void runPositiveTestCases() 
        {
             objAccountListViewTaskConPageCon =  new AccountListViewTaskCon(); 
            system.Test.startTest();
            objAccountListViewTaskConPageCon.getAccounts();
            objAccountListViewTaskConPageCon.doDelete();
            objAccountListViewTaskConPageCon.doSearch();
            objAccountListViewTaskConPageCon.first();
            objAccountListViewTaskConPageCon.last();
            objAccountListViewTaskConPageCon.previous();
            objAccountListViewTaskConPageCon.next();
            objAccountListViewTaskConPageCon.cancel();
            returnValueBooleanhasNext  = objAccountListViewTaskConPageCon.hasNext;
            returnValueBooleanhasPrevious  = objAccountListViewTaskConPageCon.hasPrevious; 
             pageNumber =  objAccountListViewTaskConPageCon.pageNumber ;
            System.assertEquals(false, returnValueBooleanhasNext  );
            System.assertEquals(false, returnValueBooleanhasPrevious  );
System.assertEquals(1, pageNumber );
system.Test.stopTest();

        }
      
}
  • March 11, 2015
  • Like
  • 0