[SalesForce] Process Builder is not validating through change set

I have a process builder which perform apex invocable action. Its working fine in dev sandbox and this are the components I have built:
1. Process Builder
2. Apex Invocable class (ProcessBuilderClass)
3. Associated test class (ProcessBuilderClass_Test)

When I run my test class in Dev sandbox, all test methods are pass. But, when I try to deploy to QA sandbox through change set where I include above components and when I validate by running my test class, it got failed.

Just for reference, here is my code:

Process Builder: My Process builder criteria: Whenever recordtype/stagename/ownerId of opportunity changes, it will call apex class. Which will update time stamp field on opportunity. And its active only
Here is my class code:

public class TestTimeStampUpdate {   
@InvocableMethod
public static void UpdateTimeStamp(List<Id> opptyIds)
{
    List<Opportunity> oppList = new List<Opportunity>();
    for(Id oppId : opptyIds) {
        Opportunity opp = new Opportunity();
        opp.Id = oppId;
        opp.TestField__c = DateTime.now().getTime();
        oppList.add(opp);
    }
    if(!oppList.isEmpty()) {              
        update oppList;
    }
}    

}

Here are my test methods that are pass in dev sandbox, but not while deploying to QA:

@isTest
private class TestTimeStampUpdate_Test {
    static testMethod void TestMethod2() {
        test.startTest();
        Opportunity opp = getOpportunity(); // Insert and return opportuntiy
        opp.StageName = '2 - StageII';
        Decimal testTS = opp.TestField__c;
        update opp;        
        Opportunity oppRec = [SELECT id,TestField__c FROM Opportunity WHERE Id =: opp.Id];
        System.assert(oppRec.TestField__c > testTS);
        test.stopTest();
    }    
    static testMethod void TestMethod1() {
        test.startTest();
        Opportunity opp = getOpportunity();
        Decimal testTS = opp.TestField__c;        
        User usr = getUser();
        opp.OwnerId = usr.Id;
        update opp;        
        Opportunity oppRec = [SELECT id,TestField__c FROM Opportunity WHERE Id =: opp.Id];
        System.assert(oppRec.TestField__c > testTS);
        test.stopTest();
    } 
}

Please help me out where I am missing ?
I really appreciate for your help.

Best Answer

Process builder deploys in an inactive state.

If test methods are written around its results snd this blocks your deployment you have the following options:

  1. Manually create the PB in production and activate it
  2. Comment out the system asserts in the test class
    • Deploy and activate the PB
    • Uncomment the asserts int he test class
    • Redeploy the test class

Also, be prepared for the test to still fail due to other processes in production that may not be in the sandbox. But at that point you can at least debug your code in production as long as the process is not a critical process that could affect day to day operations.