Unit Test for Controller that Calls a Flow

I have a controller that initiates a flow when a button is clicked on a lead. I understand that unit test classes cannot make web callouts, so I have created a class that implements the HttpCalloutMock interface as specified in this documentation. The definition of my controller is as follows:

public class ISI_Controller 
    private final Lead lead;
    public Flow.Interview.SI myFlow {get; set; }
    public String leadID;

    public ISI_Controller(ApexPages.StandardController stdController)
    this.lead= (Lead) stdController.getRecord();

    public Lead getLead()
        return lead;

So far, I have the following code that creates a lead and sets the mock http response. How do I test my controller?

public class ISI_Controller_Test 
    static testMethod void basicTest()
        Lead testLead = new Lead(LastName = 'Test',
                                 Phone = '7045555555',
                                 Company = 'Test',
                                 LeadSource = 'Telemarketing',
                                 Sales_Type__c = 'New',
                                 Customer_Type__c = 'Residential',
                                 Product_Interest__c = 'Security');
        insert testLead;

        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());

VisualForce Page Code:

<apex:page standardController="Lead" extensions="ISI_Controller" tabStyle="Lead">
<flow:interview name="ISI" interview="{!myFlow}" finishLocation="/{!Lead.Id}">
    <apex:param name="LeadID" value="{!Lead.Id}"/>  
    <apex:param name="CurrentUserID" value="{!$User.Id}"/> 
    <apex:param name="LeadOwnerID" value="{!Lead.OwnerId}"/>


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I’m assuming your flow is an interactive flow? If so, you can’t test it.

If it is a trigger-ready flow, then you need to use the start() method to trigger the flow.

Inside_Sales_Information_Controller isiController = new Inside_Sales_Information_Controller();
isiController.myflow = new Flow.Interview.SalesInformation(new Map<String, Object>());

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x