>Formula field is calculated on the fly and the values will be available **after record is committed to database**. Before saving the Opportunity ie. in before insert and update, you are checking Opportunity values, which are not available. So, in this case, `related_Partner_Supplier__c` is always `null`. 2nd thing, your trigger is not bulkified. It is always taking first account's id. 3rd thing, you have unnecessarily used DML statements in test method: Opportunity g = new Opportunity (Name = 'testOpp', AccountId = a.Id, Amount = 250, StageName = 'new', CloseDate = date.today(), related_Partner_Supplier__c = a.Id); insert g; update a; //why it is needed? update g; //why it is needed?