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
Rajesh ShahRajesh Shah 

get set test method coverage

Hi

 

I have a visualforce controller with the following kind of get method

 

 

// For error handling public Boolean error { get{ if(error == null) error = false; return error; } set; }

 I want to cover these lines in my test method.I tried using .getError() but it says method doesn't exists or in correct signature. Can someone let me knowhow to cover these lines test method?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
JPClarkJPClark

These would show up as a property, so just use the .error

 

MyController UUT = new MyController(); UUT.error = true; boolean TestError = UUT.error;

 

All Answers

bob_buzzardbob_buzzard

Are these lines showing up as not covered when you run your test?

 

In my experience, defining getter/setter through this 'decoration' mechanism, means that the methods aren't available at compile/test time.

Rajesh ShahRajesh Shah
Ya, they do show up as uncovered. I thought the getFieldName function would work but it doesn't.
JPClarkJPClark

These would show up as a property, so just use the .error

 

MyController UUT = new MyController(); UUT.error = true; boolean TestError = UUT.error;

 

This was selected as the best answer
Rajesh ShahRajesh Shah
Thanks. That does the trick. It was so simple and I was searching all over the net for the solution.
bob_buzzardbob_buzzard
Nice!  I'd given up on 100% coverage when using these getters/setters.  Thanks a bunch JP.