+ Start a Discussion
Shrey TyagiShrey Tyagi 

Test Class for Apex Invocable with Inactive process flow- Please help

Hi Everyone,
    I have a situation in which I am trying to push an apex invocable code (used by a process builder) in production . Now the process flow gets deployed as inactive flow . So in order to get coverage for my apex invocable , I am using following test class to fire the invocable . Important lines are marked in bold. Now when I run this , it does not throw any error and says 0/0 methods passed. Can someone please help me with this?
///////////////////Test Class//////////////////////////////
@isTest
private class CanInvocableHelperTest {

    @testSetup static void setup1() {

        Id currentUser = UserInfo.getUserId();
        Opportunity opp = TestUtil.setupTestData();
        opp.StageName = 'Closed Won';
        opp.Sub_Stage__c = 'Awarded';
        opp.Qty_of_CANs_Required__c = 1;
        opp.Did_Price_Change__c='No';
        update opp;
        //Updating Opportunity creates 1 can record.
        //Retrive the related CAN record using SOQL.
        CAN__c theCan = [SELECT Opportunity__c,Contract_Manager__c,Status__c,Awarded_Project__c FROM CAN__c Where Opportunity__c =:opp.Id];
        theCan.Contract_Manager__c = currentUser;
        theCan.Status__c='CP Setup';
        theCan.Awarded_Project__c='111111111';
        List<Id> TestCanIdList= new List<Id>();
        TestCanIdList.add(theCan.Id);
        // Change status to simulate process flow firing mechanism.As process flow is inactive.
        update theCan;

        Test.startTest();
        //calling invocable method here with can id
        CreateProjectRecord.ProjectRecordCreateMethod(TestCanIdList);

        
        Test.stopTest();
        }
}


///////////////////Invocable apex class////////////////////////////
public class CreateProjectRecord{ 
    
    @InvocableMethod     
    public static void ProjectRecordCreateMethod(List<Id> CanIds)     
    {        
        //Logic here
    }
}
Best Answer chosen by Shrey Tyagi
Eric PepinEric Pepin
@testSetup methods are not testMethods themselves. They are used to insert data that testMethods will use. If you only have this one method, then you don't need a @testSetup, you just need a testMethod.
Change this:
@testSetup static void setup1()
to this:
static void testMethod setup1()

Then rerun the test.

All Answers

Eric PepinEric Pepin
@testSetup methods are not testMethods themselves. They are used to insert data that testMethods will use. If you only have this one method, then you don't need a @testSetup, you just need a testMethod.
Change this:
@testSetup static void setup1()
to this:
static void testMethod setup1()

Then rerun the test.
This was selected as the best answer
Shrey TyagiShrey Tyagi
Oops Silly mistake!!! Thanks Eric!!! It worked.