+ Start a Discussion
Stephanie_ArceStephanie_Arce 

assertEquals, Expected vs Actual

I can't figure out why my test here isn't working - I get an error message indicating my expected amount is 0 but the actual is 20. 20 is what my test should be (at the end of the code block included), so I'm not sure what's wrong.

Thanks for any help!
 
@isTest

private class Test_Line_Item_Invoice_RollupTrigger {

    static testMethod void LineItemInvoiceRollupTrigger() {
    
        {   
        
    // Create a Billing Entity record, be.
    Account be = new Account();
    be.RecordTypeId = Schema.SobjectType.Account.getRecordTypeInfosByName().get('Organization').getRecordTypeId();
    be.Name = 'Test Church';
    be.Client__c = '02CRC';
    be.Active__c = True;
    be.EFT_Active__c = True;
    be.BillingStreet = '123 Test St';
    be.BillingCity = 'Grand Rapids';
    be.BillingState = 'Michigan';
    be.BillingPostalCode = '49508';
    be.Organization_Original_Auto_Number_Value__c = '1';
    insert be;

    // Create a Participant record, p, related to be.
    Contact p = new Contact();
    p.Ultipro_ID__c = 1;
    p.FirstName = 'Stephanie';
    p.LastName = 'Arce';
    p.AccountId = be.Id;
    insert p;
    
    // Create an Invoice record, i, related to be and p.
    Invoice__c i = new Invoice__c();
    i.Invoice_Date__c = Date.NewInstance(system.today().year(), system.today().month(), 15);
    i.Billing_Entity__c = be.Id;
    i.RecordTypeId = Schema.SobjectType.Invoice__c.getRecordTypeInfosByName().get('Current Month Invoice').getRecordTypeId();
    insert i;
    
    
            // Query the Invoice to ensure Line Item Total and Line Item Total Adjusted are $0.00
            Invoice__c query1 = [select Id, Line_Item_Total__c, Line_Item_Total_Adjusted__c, Number_of_Line_Items__c from Invoice__c where Id = :i.Id];
            system.assertEquals(query1.Line_Item_Total__c, 0);
            system.assertEquals(query1.Line_Item_Total_Adjusted__c, 0);
            system.assertEquals(query1.Number_of_Line_Items__c, 0);

/*
------------------------------------
    Insert Test
------------------------------------
    
            // Create a Line Item record, ilicurrentinsert1, related to i and p. Inserting should cause the trigger to run.
            Line_Item__c ilicurrentinsert1 = new Line_Item__c();
            ilicurrentinsert1.Invoice__c = i.Id;
            ilicurrentinsert1.Participant__c = p.Id;
            ilicurrentinsert1.Benefit__c = 'Medical';
            ilicurrentinsert1.Plan_Option__c = 'Single HDHP - Full Time';
            ilicurrentinsert1.Ultipro_Benefit_Group__c = 'US Church';
            ilicurrentinsert1.Ultipro_Deduction_Code__c = 'MED';
            ilicurrentinsert1.Cost__c = 20;
            ilicurrentinsert1.Premium_Month__c = 'Jan';
            ilicurrentinsert1.RecordTypeId = Schema.SobjectType.Line_Item__c.getRecordTypeInfosByName().get('Existing Invoice Line Item').getRecordTypeId();
            insert ilicurrentinsert1;
    
                    // Query the Invoice to see if the amount in the Line Item was updated to Line Item Total on their record.
                    Invoice__c query2 = [select Id, Line_Item_Total__c, Line_Item_Total_Adjusted__c, Number_of_Line_Items__c from Invoice__c where Id = :i.Id];
                    system.assertEquals(query2.Line_Item_Total__c, 20);
                    system.assertEquals(query2.Number_of_Line_Items__c, 1);

 
Best Answer chosen by Stephanie_Arce
YuchenYuchen
Can you print some debug logs for the ilicurrentinsert1 and query2 to see what values get printed? I did not see the trigger here, so, when you do the testing from front end, does it work as expected? 

All Answers

YuchenYuchen
Can you print some debug logs for the ilicurrentinsert1 and query2 to see what values get printed? I did not see the trigger here, so, when you do the testing from front end, does it work as expected? 
This was selected as the best answer
Stephanie_ArceStephanie_Arce
I found out this was happening when I had a particular workflow rule activated - my logic set up in it wasn't correct, so it was running on this inserted record when I didn't think it was.

Thanks!