[SalesForce] 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?

@isTest
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.startTest();
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        Test.stopTest();
    }
}

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}"/>
 </flow:interview>

Best Answer

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>());
isiController.myflow.start();
Related Topic