When writing a testMethod I am unable to retrieve related contact fields. In the example below I would expect the final assert to return true. The code I am testing works fine, the select is only failing in a testing context.
Why is the Contact info no being returned from the SOQL query?
static testMethod void FailTest()
{
Contact client = new Contact(FirstName='TestFirst1', LastName='TestFirst', BirthDate = Date.parse('01/01/1986'), Gender__c = 'Male');
insert client;
Opportunity opp = new Opportunity(Name = 'Test Opp' + Math.random(), CloseDate=Date.Today(), StageName='ASR - Case Design', Product_Types__c='UL', Face_Amount_Applied_For__c=500, Estimated_Target_Premium__c=1000, X1st_Client__r = client);
insert opp;
Opportunity selectOpp = [Select o.X1st_Client__r.LastName From Opportunity o WHERE o.Id = :opp.Id LIMIT 1];
system.assertNotEquals(opp.X1st_Client__r.LastName, null); //true
system.assertNotEquals(opp.Name, null); //true
system.assertNotEquals(selectOpp.Name, null); //true
system.assertNotEquals(selectOpp.X1st_Client__r.LastName, null); //false, should be true
}