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
SarisfdcSarisfdc 

Test Class for the String and Boolean getter

I have a string boolean whose value I am using in Javascript on VF page, How do I get the code coverage of the same in test class
   
Public id guestuserid=[select id from user where Name =: 'Guest User' limit 1].id;
  public string Usertype {get {  
           if (UserInfo.getUserId() != guestuserid)  
           return 'APP USER';  
          else
           return 'GUEST';  
        }}
And for the boolean getter, in below code Offset is integer having value zero asssigned.
public Boolean PreviousNew { get {
        if (offset>0) return false; else return true;
    }}

Please help me to write the test class for these.

Thanks!
Best Answer chosen by Sarisfdc
JethaJetha
As you said, this variable is only used in visualforce javascript and not in controller anyware. So in that case you need to call this variable explicitly as below :

YourClass var = new YourClass();
var temp = var.PreviousNew; //just used for coverage (include this line in your page anywhere)

Thanks
 

All Answers

JethaJetha
As you said, this variable is only used in visualforce javascript and not in controller anyware. So in that case you need to call this variable explicitly as below :

YourClass var = new YourClass();
var temp = var.PreviousNew; //just used for coverage (include this line in your page anywhere)

Thanks
 
This was selected as the best answer
SarisfdcSarisfdc
Thanks Jetha! 
It worked :)