I created a field on the Account object called In_Negotiation__c, it's a picklist with options 'True' and 'False' with a default value of 'False'. (Yes, I know it would make more sense to have it be a boolean/checkbox, but there are valid reasons to make it a picklist that I can't get into here)
When I create a new Account in the normal point-and-click interface, the field successfully defaults to 'False'. I've also created a before insert/before update trigger to set the value of this field (looks at the Accounts opportunities and determines whether there exists an opportunity that fits our definition of "in negotiation"). This should mean the field always has a value of either 'True' or 'False'.
However, in my unit test, it seems that after the initial creation of a test Account, the field value comes back NULL.
Here is my Unit Test code:
@istest static void test_setInNegotiation() {
Account a = new Account();
a.Name = 'account';
insert a;
system.assertEquals('False', a.In_Negotiation__c, 'In_Negotiation__c is not defaulted to False!');
Opportunity o = new Opportunity();
o.Name = 'opp';
o.StageName = 'Active Discussion';
o.Type = 'New Business';
o.CloseDate = date.today().addDays(15);
o.Amount = 990;
o.AccountId = a.id;
insert o;
system.assertEquals('False', a.In_Negotiation__c, 'In_Negotiation__c is not False when it should be!');
o.StageName = 'Negotiation';
update o;
system.assertEquals('True', a.In_Negotiation__c, 'In_Negotiation__c is not True when it should be!');
o.Type = 'Upgrade';
update o;
system.assertEquals('True', a.In_Negotiation__c, 'In_Negotiation__c is not True when it should be!');
o.Type = 'Annual Renewal';
update o;
system.assertEquals('True', a.In_Negotiation__c, 'In_Negotiation__c is not True when it should be!');
o.CloseDate = date.today().addDays(-400);
update o;
system.assertEquals('False', a.In_Negotiation__c, 'In_Negotiation__c is not False when it should be!');
o.CloseDate = date.today().addDays(15);
o.Type = 'Monthly Renewal';
update o;
system.assertEquals('False', a.In_Negotiation__c, 'In_Negotiation__c is not False when it should be!');
}
When I run it, I'm getting the error System.AssertException: Assertion Failed: In_Negotiation__c is not defaulted to False!: Expected: False, Actual: null
Why would this be happening? Why is the value of the field not 'False'?