I am encountering something odd with this test class, and I either do not know how to phrase my issue, or it is just odd.
I have 2 triggers that I am checking. The first trigger is on an Opportunity. If I update any of a handful of fields, the trigger will update some corresponding fields on the account and all other open opportunities that are linked to that account. The second trigger is on the Account, if those same fields are updated on the Account, the second trigger will update all open Opportunities. I got my triggers set so that firing off 1 does not trigger the other. It is all working nicely in the Sandbox.
I am trying to write my test class so that I can promote this to my production instance, and am getting this issue.
The test class is set to insert an Account and Opportunity. Then, update the Account fields to check that the second trigger mentioned above fires. I am getting an error on my "system.assertequals(oCheck[0].Current_CBRN__c,'LION'" line near the bottom of the test.
System.AssertException: Assertion Failed: Expected: TexShield, Actual: LION
Here is my test code.
@isTest(SeeAllData=true)
public class TestAccountUpdateOpenOpp {
public static testmethod void test() {
Account aMain = New Account();
aMain.Name = 'Trigger Test Account CT';
aMain.ShippingCountryCode = 'US';
aMain.ShippingStateCode = 'CT';
aMain.Type = 'Lion';
aMain.County__c = 'Armstrong';
aMain.Current_CBRN__c = 'TexShield';
aMain.Current_Cleaning_and_Repair__c = 'Firecare Services';
aMain.Current_Footwear__c = 'HAIX';
aMain.Current_Gloves__c = 'ESKA';
aMain.Current_Helmets__c = 'Honeywell';
aMain.Current_Turnouts__c = 'Globe';
aMain.Current_Uniforms__c = '5.11 Tactical';
insert aMain;
system.assertequals(aMain.Current_CBRN__c,'TexShield');
system.assertequals(aMain.Current_Cleaning_and_Repair__c,'Firecare Services');
system.assertequals(aMain.Current_Footwear__c,'HAIX');
system.assertequals(aMain.Current_Gloves__c,'ESKA');
system.assertequals(aMain.Current_Helmets__c,'Honeywell');
system.assertequals(aMain.Current_Turnouts__c,'Globe');
system.assertequals(aMain.Current_Uniforms__c,'5.11 Tactical');
list<Opportunity> oList = new list<Opportunity>();
Opportunity o = New Opportunity();
o.accountid = aMain.id;
o.name = 'test';
o.CloseDate = System.Today();
o.StageName = 'Stage 1 - Qualify';
insert o;
oList.add(o);
Opportunity o2 = New Opportunity();
o2.accountid = aMain.id;
o2.name = 'test';
o2.CloseDate = System.Today();
o2.StageName = 'Stage 1 - Qualify';
insert o2;
oList.add(o2);
oList = [select id, current_CBRN__c, Current_Cleaning_and_Repair__c, Current_Footwear__c, Current_Gloves__c, Current_Helmets__c, Current_Turnouts__c, Current_Uniforms__c from Opportunity where id in :oList];
system.assertequals(oList[0].Current_CBRN__c,'TexShield');
system.assertequals(oList[0].Current_Cleaning_and_Repair__c,'Firecare Services');
system.assertequals(oList[0].Current_Footwear__c,'HAIX');
system.assertequals(oList[0].Current_Gloves__c,'ESKA');
system.assertequals(oList[0].Current_Helmets__c,'Honeywell');
system.assertequals(oList[0].Current_Turnouts__c,'Globe');
system.assertequals(oList[0].Current_Uniforms__c,'5.11 Tactical');
list<Account> aList = [select id, current_CBRN__c, Current_Cleaning_and_Repair__c, Current_Footwear__c, Current_Gloves__c, Current_Helmets__c, Current_Turnouts__c, Current_Uniforms__c from Account where id = :aMain.id];
aList[0].Current_CBRN__c = 'LION';
aList[0].Current_Cleaning_and_Repair__c = 'LION TotalCare';
aList[0].Current_Footwear__c = 'LION / STC';
aList[0].Current_Gloves__c = 'LION';
aList[0].Current_Helmets__c = 'LION';
aList[0].Current_Turnouts__c = 'LION';
aList[0].Current_Uniforms__c = 'LION';
update aList;
list<Account> aCheck = [select id, current_CBRN__c, Current_Cleaning_and_Repair__c, Current_Footwear__c, Current_Gloves__c, Current_Helmets__c, Current_Turnouts__c, Current_Uniforms__c from Account where id = :aMain.id];
system.assertequals(aCheck[0].Current_CBRN__c,'LION');
system.assertequals(aCheck[0].Current_Cleaning_and_Repair__c,'LION TotalCare');
system.assertequals(aCheck[0].Current_Footwear__c,'LION / STC');
system.assertequals(aCheck[0].Current_Gloves__c,'LION');
system.assertequals(aCheck[0].Current_Helmets__c,'LION');
system.assertequals(aCheck[0].Current_Turnouts__c,'LION');
system.assertequals(aCheck[0].Current_Uniforms__c,'LION');
list<Opportunity> oCheck = [select id, current_CBRN__c, Current_Cleaning_and_Repair__c, Current_Footwear__c, Current_Gloves__c, Current_Helmets__c, Current_Turnouts__c, Current_Uniforms__c from Opportunity where id = :o.id];
system.assertequals(oCheck[0].Current_CBRN__c,'LION');
system.assertequals(oCheck[0].Current_Cleaning_and_Repair__c,'LION TotalCare');
system.assertequals(oCheck[0].Current_Footwear__c,'LION / STC');
system.assertequals(oCheck[0].Current_Gloves__c,'LION');
system.assertequals(oCheck[0].Current_Helmets__c,'LION');
system.assertequals(oCheck[0].Current_Turnouts__c,'LION');
system.assertequals(oCheck[0].Current_Uniforms__c,'LION');
}
}
The error is saying that it is expecting the old value, but it is finding the new value. How can it be finding the new value and expecting the old?
I can post the specific trigger that this one is firing if needed.
Any help would be appreciated.
Thanks.
Edit I switched the assertionequals values, which is now showing me that my trigger is not processing. The trigger works for normal Sandbox Data. So, I suspect that I have an issue with my Test Class.
But, here is the trigger that I using.
trigger UpdateOpenOppCurrentGear on Account (before update) {
if(checkRecursive.runOnce()){
List<Opportunity> updatedOpps = new List<Opportunity>();
List<Account> changedAccounts = new List<Account>();
for(Account aNew : Trigger.New) {
for(Account aOld : Trigger.Old) {
Boolean updated = False;
if(aNew.Current_CBRN__c != aOld.Current_CBRN__c){
updated = True;
}
if(aNew.Current_Cleaning_and_Repair__c != aOld.Current_Cleaning_and_Repair__c){
updated = True;
}
if(aNew.Current_Footwear__c != aOld.Current_Footwear__c){
updated = True;
}
if(aNew.Current_Gloves__c != aOld.Current_Gloves__c){
updated = True;
}
if(aNew.Current_Helmets__c != aOld.Current_Helmets__c){
updated = True;
}
if(aNew.Current_Turnouts__c != aOld.Current_Turnouts__c){
updated = True;
}
if(aNew.Current_Uniforms__c != aOld.Current_Uniforms__c){
updated = True;
}
if(updated == True){
changedAccounts.add(aNew);
}
}
}
if (changedAccounts.size() > 0){
for(Opportunity o: [select id, accountid, current_CBRN__c, current_cleaning_and_repair__c, current_footwear__c, current_gloves__c, current_helmets__c, current_Turnouts__c, current_uniforms__c from Opportunity where isclosed = false and accountid in :changedAccounts]){
account a = trigger.newmap.get(o.accountid);
o.Current_CBRN__c = a.Current_CBRN__c;
o.Current_Cleaning_and_Repair__c = a.Current_Cleaning_and_Repair__c;
o.Current_Footwear__c = a.Current_Footwear__c;
o.Current_Gloves__c = a.Current_Gloves__c;
o.Current_Helmets__c = a.Current_Helmets__c;
o.Current_Turnouts__c = a.Current_Turnouts__c;
o.Current_Uniforms__c = a.Current_Uniforms__c;
updatedOpps.add(o);
}
}
if (updatedOpps.size() > 0){
update updatedOpps;
}
}
}
When I look at the developer console, I see that the if(aNew.Current_CBRN__c != aOld.Current_CBRN__c) line is being read, and skipped. However, my test class is updating the record according to the assertequals lines.
Does anything in the test class look off, other than the assertequals being in the wrong order? Maybe I am not actually updating the account record?