-3

Apex Class

public class Controll{   
 public ApexPages.StandardSetController paged {
         get {
              if(paged == null) {
               paged = new ApexPages.StandardSetController(Database.getQueryLocator(
               [SELECT Name,age__c from Account]));
             }
             paged.setPageSize(20);
             return paged;
            }
            set;
          }
    public controll(){

    }
 }

Test Class

@isTest
public class Controll_Test {

public static testmethod void ControlTest(){

 Account a=new Account();
 a.name='usdf';
 insert a;
 test.starttest();
 Controll co=new Controll();
  ApexPages.StandardSetController ssc = 
new ApexPages.StandardSetController(Database.getQueryLocator([select name from Account where name='usdf']));
       co.paged=ssc;
       test.stoptest();

}

}

Only this line is covered in my test class

"public ApexPages.StandardSetController paged {"

1

if you try to access the variable in your test method, the getter will be executed and you will be covering the variable.

    @istest
    public class testClass{
      @istest
      static void test(){
           MySampleClass cls = new MySampleClass();
           Sytem.assertNotEqual(cls.paged,null);

  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.