You need to sign in to do that
Don't have an account?
Ajay Kumar 261
Test class Assertion issue
Hi,
My Class:
Issue: I am having issue with assert statement.
16:48:04.0 (948783585)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 400, Actual: null Class.yearup_opportunityTriggerHandlerTest.myUnitTest: line 21, column 1 16:48:04.0 (948790277)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 400, Actual: null Class.yearup_opportunityTriggerHandlerTest.myUnitTest: line 21, column 1
Can anyone help me what am I missing?
Regards,
Ajay
My Class:
public static void UpdateDevAmountAndAmountOppty (List<Opportunity> OptyTriggerNewList, Map<Id,Opportunity> OptyTriggerOldMap, String sOperation) { Set<Id> oppsIds = new Set<Id>(); List<Opportunity> renewalOpps = new List<Opportunity>(); List<Opportunity> OppsList = new List<Opportunity>(); for( Opportunity opp : OptyTriggerNewList ) { if(sOperation=='sInsert'){ if(opp.Dev_Amount__c!=null){ Opp.Amount = opp.Dev_Amount__c; }else if(opp.Amount !=null){ Opp.Dev_Amount__c = opp.Amount; } } if(sOperation=='sUpdate' && opp.StageName != 'Solicit: Gift Closed/Received 100%'){ Opportunity oldOpp = OptyTriggerOldMap.get(opp.Id); if(opp.Dev_Amount__c <> null && oldOpp.Dev_Amount__c <> opp.Dev_Amount__c && Opp.Amount <> opp.Dev_Amount__c){ Opp.Amount = opp.Dev_Amount__c; }else if(opp.Amount <> null && oldOpp.Amount <> opp.Amount && opp.Dev_Amount__c <> Opp.Amount){ Opp.Dev_Amount__c = opp.Amount; } } } }Test Class:
static testMethod void myUnitTest() { Test.startTest(); Opportunity testopp = new Opportunity(); testopp.name = 'testOpp'; testopp.Site__c = 'National'; testopp.Category__c ='New Opportunity'; testopp.Cohort__c = 'January 2016'; testopp.CloseDate = System.today()+10; testopp.LeadSource = 'Channel Partners'; testopp.Stagename = 'Identification: 0%'; testopp.Restriction_picklist__c = 'Unrestricted'; testopp.Ask_Amount__c = 200; testopp.Amount = 1200; testopp.Type = 'Individual'; insert testopp; //Start test system.assertequals(1200,testopp.Dev_Amount__c); Opportunity opp= [select id, Stagename, Amount, Dev_Amount__c from Opportunity where id =:testopp.id ]; opp.Dev_Amount__c = 1500; update opp; System.debug('opp.Dev_Amount__c '+opp.Dev_Amount__c); system.assertequals(1500,opp.Amount); Test.stopTest(); }
Issue: I am having issue with assert statement.
16:48:04.0 (948783585)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 400, Actual: null Class.yearup_opportunityTriggerHandlerTest.myUnitTest: line 21, column 1 16:48:04.0 (948790277)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 400, Actual: null Class.yearup_opportunityTriggerHandlerTest.myUnitTest: line 21, column 1
Can anyone help me what am I missing?
Regards,
Ajay
While that error probably came from another class, I can tell you why you're having problems with the unit test you've posted. Once you've invoked a trigger (e.g. by doing an insert or update), the version of your record in memory no longer matches the data stored in the database. Therefore, you need to make sure you remember to query the data back from the database before you perform your assert's. Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue which results in helping others who are really in need of it.
Best Regards,
Nagendra.P