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
jordanmjordanm 

Test Class for Controller/Flow:Interview

Hello,

 

I am only getting 66% coverage with the following code, and was wondering how to go about getting full. The lack of coverage happens when the flow/interview is NOT null, but I'm not sure how to give it a value.

 

Here is my VF page:

<apex:page controller="IntakeController" tabStyle="Case" >
    <flow:interview name="Universal_Intake" finishLocation="{!FinishPage}"
        interview="{!myflow}" />
    <apex:PageBlock >
        <apex:outputText style="font-size:150%; color:red; font-weight:bold" 
        value="NOTE: Editing/Deleting below this point will interrupt your Universal Intake flow!" />
        <apex:detail subject="{!var_ParticipantId}" relatedList="true" />
    </apex:PageBlock>
        <apex:PageBlock >
        <apex:detail subject="{!var_FamilyId}" relatedList="true" />
    </apex:PageBlock>
</apex:page>

My Controller:

public class IntakeController {

    public Flow.Interview.Universal_Intake myflow {get;set;}
     
    public String getVar_ParticipantId() {
        if (myflow==null) return '';
        else return myflow.var_ParticipantId;
    }
    
    public String getVar_FamilyId() {
        if (myflow==null) return '';
        else return myflow.var_FamilyId;
    }
    
    public String getVar_AddressId() {
        if (myflow==null) return '';
        else return myflow.var_AddressId;
    }

    public PageReference getFinishPage(){
        //does address ID exist?
        if (getVar_AddressId()=='')
        {
        //no, use family ID instead which will exist
        PageReference p = new PageReference('/' + getVar_FamilyId() );
        p.setRedirect(true);
        return p;
        }
        else
        {
        //yes, use addressID
        PageReference p = new PageReference('/' + getVar_AddressId() );
        p.setRedirect(true);
        return p;
        }
    }
}

 

My Test class:

@isTest
public class TestIntakeController {

    public static testMethod void testMyController() {
              
        IntakeController controller = new IntakeController();
        
        PageReference testFinishPage = controller.getFinishPage();
        
        String GetParticipantId = controller.getVar_ParticipantId();
        String GetFamilyId = controller.getVar_FamilyId();
        String GetAddressId = controller.getVar_AddressId();
        
        }
}

 

I know I have to account for interviews that are NOT null, but again, am not sure how to do so. Any help would be appreciated.

 

NOTE: I do know about the flow designer forums, but posted here instead because those boards seem much less active than these. Apologies.

ken92ken92

I have this same problem....can you help me?

Gigi.OchoaGigi.Ochoa

has anyone figured out how to write a test class for Flow.interview?

DarrellDDarrellD

You cannot instantiate (call) a flow from a test class yet, they are working on it. If its part of a VF page, you can write some code for the page but can't actually call the Flow.  I'm sure it's coming.

 

Darrell