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
SFDCDevQASFDCDevQA 

Asserts failing when correct

My Test Class is failing in the last two assert lines saying that "System.AssertException: Assertion Failed: Expected: Confirmed Teaching/Class Schedule, Actual: Confirmed Use" and "System.AssertException: Assertion Failed: Expected: null, Actual: Sent" BUT that is what I am telling it to Assert.  Is the wording backwards somehow?  It reads as if it wants what it started with instead of what I told it that it should end up with.

Thanks so much,

Amanda

 

@IsTest
private class TestQuoteAASentUpdateOppCreateCourses
{
    private static TestMethod void testTrigger(){
        
        //Step 1 : Data Insertion
        Account a=new Account(Name='Test Account');
           insert a;
           Contact c = new Contact(FirstName='John',LastName='Doe');
        insert c;
        Opportunity o = new Opportunity(Name='Test Opportunity',closedate=system.today(), stagename='Confirmed Teaching/Class Schedule',Probability=0.95);
        insert o;      
        OpportunityContactRole ocr = new OpportunityContactRole (OpportunityID = o.id, ContactID=c.id, role='Decision Maker') ;     
        insert ocr;  
        Quote q= new Quote (Name='Test Quote', ContactID=c.id, OpportunityID=o.id);
        insert q;
        Task t= new Task (Subject='Email: Sapling Learning Adoption Agreement', WhoID=c.id, WhatID=q.id);
        insert t;
        
        test.startTest();
        
        //Perform the dml action on which trigger gets fired , like insert, update ,delete , undelete.  In this case updade the quote.
       q.Adoption_Agreement_Sent__c = Date.today();
       update q;
       
        // check that the new course was created successfully and opp and quote updates were successful
        System.assertEquals(o.Stagename, 'Confirmed Use');
        System.assertEquals(q.Status, 'Sent');

        Course__c newCS = [select ID, Name, Adoption_Agreement__c, Opportunity__c, Contact__c from Course__c LIMIT 1];
        System.assertNotEquals(newCS, null);
        System.assertEquals(c.Id, newCS.Contact__c);
        System.assertEquals(o.Id, newCS.Opportunity__c);
        System.assertEquals(q.Id, newCS.Adoption_Agreement__c);
       
        
        // Switch back to runtime context
        Test.stopTest();
        
    }
}

jbroquistjbroquist

You have the parameters in your assertions reversed. In a System.assertEquals(param1, param2) call, the first parameter is generally the value you are expecting, where the second parameter is the actual value. Hope that makes sense.

 

You will also need to re-query the value of the opportunity fields if the update to the Quote record is supposed to change the stage of the Opportunity.

SFDCDevQASFDCDevQA

For some reason I'm drawing a blank on how to requery the opportunity without having it give me errors saying I'm recreating an opp  with the same name.  it wouldn't let me do the WHERE function when I tried to do

 // check that the new course was created successfully and opp and quote updates were successful
        Opportunity O = [select id, stagename from Opportunity where id=o.id]
        System.assertEquals('Confirmed Use',o.Stagename);
        System.assertEquals('Sent',q.Status);
        Course__c newCS = [select ID, Name, Adoption_Agreement__c, Opportunity__c, Contact__c from Course__c LIMIT 1];
        System.assertNotEquals(newCS, null);
        System.assertEquals(c.Id, newCS.Contact__c);
        System.assertEquals(o.Id, newCS.Opportunity__c);
        System.assertEquals(q.Id, newCS.Adoption_Agreement__c);
        
       

dlvdlv
Did you ever solve this? I'm having the exact same issue and I'm stumped.