1

How do i get coverage for this type of {get;set;}?

Apex class:

public Boolean viewMode {get;set;}
     public Boolean editMode {get;set;}
      public Boolean hasError {
        get {
            if(hasError == null)
                hasError = false;
            return hasError;
        }
        set;        
    }

Test Method:

   apvc.viewMode =true;
   apvc.editMode =true;
   apvA.hasError=null;

enter image description here

I get the following error

System.AssertException: Assertion Failed

when the test method is modified as

apvA.hasError = null; 
       System.assert(apvA.hasError == null);

but coverage is attained

1 Answer 1

1

Currently you're covering the setter only by setting value to that variable. Try retrieve the value:

Boolean testError = apvA.hasError;
System.assert(testError == false);
3
  • System.AssertException: Assertion Failed - error is thrown while i run the test class
    – Azeem
    Aug 12, 2015 at 7:05
  • I can't see the rest of your code, but this is how you should solve your problem Aug 12, 2015 at 7:17
  • the error is in the System.assert(testError == false); statement... is there any other way
    – Azeem
    Aug 12, 2015 at 7:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .