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
roni shoreroni shore 

cover boolean variable in test calss

Public Class Customer_Controller{
    
    ApexPages.StandardController controller;
     @TestVisible private final Case thisCase;

    public Customer_Controller(ApexPages.StandardController controller) {
        this.controller = controller;
        this.thisCase = (Case)controller.getRecord();
    }
    public Boolean isTScase {
        get {
            return (((String)thisCase.RecordTypeId).left(15) == Label.Caseod_RecordType);
        }
    }
    public Boolean isCScase {
        get {
            return (((String)thisCase.RecordTypeId).left(15) == Label.Casenew_recordtype);
        }
    }

error : Compile Error: Variable is not visible:
Best Answer chosen by roni shore
Raj VakatiRaj Vakati
This below code will give 100 % coverage .. Change the record type name and page name 

 
@isTest
public class Customer_Controller_Test {
    
    private static testmethod void testcase1(){
        
        //create account
        Account acc = new Account();
        acc.Name='Test' ; 
        //enter details  
        insert acc;
        
        
        Id RecordTypeIdCase = Schema.SObjectType.Case.getRecordTypeInfosByName().get('asd').getRecordTypeId();

        
        
        //create case
        Case c = new Case();
        c.RecordTypeId = RecordTypeIdCase;
        //enter details
        c.AccountId = acc.Id;
        c.Subject='working';
        c.Type = 'My Type';
        c.Origin = 'My Origin';
        c.Status = 'My Status';
        insert c;
        ApexPages.StandardController sc = new ApexPages.StandardController(c);
        Customer_Controller tescon = new Customer_Controller(sc);
        
        PageReference pageRef = Page.casesc;
        pageRef.getParameters().put('id', String.valueOf(c.Id));
        Test.setCurrentPage(pageRef);
        
        Boolean csId =  tescon.isTScase ;
        Boolean csId2 =tescon.isCScase ;
        
    } 
    
}

 

All Answers

Raj VakatiRaj Vakati
This below code will give 100 % coverage .. Change the record type name and page name 

 
@isTest
public class Customer_Controller_Test {
    
    private static testmethod void testcase1(){
        
        //create account
        Account acc = new Account();
        acc.Name='Test' ; 
        //enter details  
        insert acc;
        
        
        Id RecordTypeIdCase = Schema.SObjectType.Case.getRecordTypeInfosByName().get('asd').getRecordTypeId();

        
        
        //create case
        Case c = new Case();
        c.RecordTypeId = RecordTypeIdCase;
        //enter details
        c.AccountId = acc.Id;
        c.Subject='working';
        c.Type = 'My Type';
        c.Origin = 'My Origin';
        c.Status = 'My Status';
        insert c;
        ApexPages.StandardController sc = new ApexPages.StandardController(c);
        Customer_Controller tescon = new Customer_Controller(sc);
        
        PageReference pageRef = Page.casesc;
        pageRef.getParameters().put('id', String.valueOf(c.Id));
        Test.setCurrentPage(pageRef);
        
        Boolean csId =  tescon.isTScase ;
        Boolean csId2 =tescon.isCScase ;
        
    } 
    
}

 
This was selected as the best answer
Narender Singh(Nads)Narender Singh(Nads)
Hi,
Please make sure you are reference your method using an object of controller class, not by the name(because your class method is not static).
Reference it like this:
Customer_Controller obj= new Customer_Controller();
Boolean Flag= ​obj.isTScase;

Thanks!