+ Start a Discussion
Laura LiveseyLaura Livesey 

Assertion fails in test class when deploying to production - works in sandbox

I'm trying to deploy and am getting an error with a test class that works fine in sandbox - please help!  Here is the test class:

public class BTProbityCheckTest {

    static testMethod void myBTSendProbityCheckTest(){
    Contact newCandy = new Contact (FirstName='Fred', LastName='Flintstone', email='test@testing.com');
    insert newCandy;
    BT_Probity_Check__c newBTPC = new BT_Probity_Check__c(Candidate__c= newCandy.id);
    insert newBTPC; 

    PageReference pageRef = Page.BTSendProbityCheck;
    pageRef.getParameters().put('id', newBTPC.id);
    ApexPages.StandardController sc = new ApexPages.standardController(newBTPC);
    BTSendProbityCheckExtension e = new BTSendProbityCheckExtension(sc); 
    System.assertEquals(newBTPC.id, e.btpc.id );
    System.assertEquals('test@testing.com', e.btpcEmail);
    System.assertEquals('Fred Flintstone',e.btpc.Full_Name__c); 
    System.assertEquals(String.valueOf(newCandy.Id), e.btpcCandy);

The error I get when trying to deploy is:

System.AssertException: Assertion Failed: Expected: Fred Flintstone, Actual: null
Stack Trace: Class.BTProbityCheckTest.myBTSendProbityCheckTest: line 24, column 1

The line is 
System.assertEquals('test@testing.com', e.btpcEmail);

Thanks in advance. 
Bryan TelfordBryan Telford
Without knowing the differences between your sandbox and production environments, have you considered this instead?

    System.assertEquals('test@testing.com', newCandy.Email);
    System.assertEquals('Fred Flintstone',newCandy.Name); 

I don't see where you are inserting the field "Full_Name__c", which is probably why it gets the assertion exception Assertion Failed: Expected: Fred Flintstone, Actual: null
Laura LiveseyLaura Livesey
omg so simple! thanks Bryan - it was doing my head in!. 
Bryan TelfordBryan Telford
Glad it worked!