function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

helping testing cover code

I have a long trigger with many "if" where I don't know how to test it. This is one of the "if" which I don't know how to test...

list_opp is a list of id of opportunity and work properly, the trigger before update save the custom field sex of opportunity into the custom field of contact




if (list_opp.get(0).sex__c <> null){ c.sesso__c = list_opp.get(0).sex__c;}



 I thinking to do this but doesn't work:



Account a = new account(name = 'Test ammin'); insert a; Contact c = new contact(lastname='test_last_name',; insert c; Opportunity o = new Opportunity(name='Name test',sex = 'M'); insert o OpportunityContactRole z = new OpportunityContactRole(,,role='other',Isprimary=true); insert z; //now verify if sex is write properly Contact c2 = [select sex__c from contact where limit 1]; system.assertequals(o.sex__c,c2.sex__c);

 the test say me:


System.Exception: Assertion Failed: Expected: M, Actual: null  






In your test you refer to a custom field 'sex__c' on opportunity (in your list).  Then when setting up the data you miss the '__c' (sex = 'M').  Are you sure you have successfully compiled this.  I have done this myself in eclipse - looking at the run tests window rather than the problems ?
Sorry I write bad into the post, but in eclipse i write it ok!