You need to sign in to do that
Don't have an account?
Marc G.ax1040
Test class assertion error, Plz Help !
Hi ,
I need help in fixing the assertion issue in this test class. I have 2 objects with Start_Term__c fields on both Opportuntiy and Contact respectively . My trigger basicallly updates the Start_Term__c field on contact.
***************************************************************************************/
@isTest private class opportunity_syncStartTermTest { static testmethod void test() { Contact newcontact = new Contact(LastName = 'abc', Start_Term__c = 'Jan 2012' ); insert newcontact; Opportunity newopportunity = new Opportunity( Contact__c = newcontact.Id, Name = 'abc', StageName = 'StageName', Start_Term__c = 'Jan 2012', CloseDate = Date.today() ); insert newopportunity; Test.startTest(); newopportunity.Start_Term__c = 'Sep 2011'; update newopportunity; Test.stopTest(); Contact[] message = [SELECT Id, Start_Term__c,Program_Primary__c FROM Contact WHERE ID = :newcontact.Id limit 1]; if(message.size() > 0) { System.assert(message[0].Start_Term__c == 'Sep 2011'); } } } }
Thanks for your help
Your test class seems okay. Perhaps your trigger needs a second look. You're not by any chance rejecting a month in the past, i.e. Sep 2011.
HI Ritesh,
I tested it with Sep 2014 , it is not working. The code is working perfect too only thing it's failing is assertion
Chances are your trigger isn't doing what you think it is. Try using assertequals so you can see that the value of the message[0].Start_Term__c is. I bet it that it is still 'Jan 2012'.
Best,
Mike
HI Mike,
Yes, the value is still Jan 2012 after using assert equal but i don't understand why is the trigger working and the assertion not . In the UI I don't have any problem updating the record on other object.. Please help
There could be a lof of reasons. Add some system.debug statements to your trigger.Take a look at the debug log that is generated when you run your unit test. Verify that the trigger is running as you expect.
I echo Mike's comments -- you need debug statements in the Trigger code, not just in the testmethod. This way you can rule out whether there is some subtle difference in how your trigger responds in a UI scenario versus a testmethod