+ Start a Discussion

check method in test class

how can i check the line showProject4 = true in my test class?

public Boolean showProject4 {get;set;}
public void ProjButton3() { if(leave.Project_1__c != null && leave.Project_2__c != null && leave.Project_3__c != null) { showProject4 = true; } else { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please select projects.'); ApexPages.addMessage(myMsg); showProject4 = false; } }

i have this in my test class: 


but when i check it in the devconsole, line showProject4 = true isn't checked.



Best Answer chosen by Admin (Salesforce Developers) 

In your test method, before you call controller.ProjButton3();, make sure that you create an instance of leave oebject and populate the values for all three i.e. Project_1__c,Project_2__c  and Project_3__c.