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
dianassdianass 

system.assertEquals Failure on Test Class

I am getting a system.assertEquals error on the following test class. Error: System.AssertException: Assertion Failed: Expected: null, Actual: 00580000001k6g1AAAClass.testReferralAssignOwner.test: line 11, column 1 Test Class: @isTest private class testReferralAssignOwner { static testMethod void test() { List testUsers = [select id from user where isactive = true limit 2]; Account a = new Account(Name='test'); insert a; List refs = new List(); refs.add(new Referral__c(Client_Name__c=a.id,Phone__c='12345',Assigned__c=testUsers[0].Id)); refs.add(new Referral__c(Client_name__c=a.id,Phone__c='12345',Assigned__c=testUsers[1].Id)); insert refs; system.assertEquals(refs[0].OwnerId,testUsers[0].Id); // OwnerId should equal Assigned__c; system.assertEquals(refs[1].OwnerId,testUsers[1].Id); // OwnerId should equal Assigned__c; refs[0].OwnerId = testUsers[1].Id; refs[1].Assigned__c = testUsers[0].Id; update refs; system.assertEquals(refs[0].Assigned__c,testUsers[1].Id); // Assigned__c should equal OwnerId now system.assertEquals(refs[1].OwnerId,testUsers[0].Id); // OwnerId should equal Assigned__c now } } It says that it is expecitng null and getting a user ID instead. It should be expecting the user ID, so I am not sure what the problem is. Any help is greatly appreciated!
bob_buzzardbob_buzzard

Can you post your code using the clipboard icon with a 'c' embedded - that will preserve the formatting and allow us to read it!

Sam27Sam27

Hi dianass,

 

well I am not sure which system.assert is there on line 11....since the test code you provided is not in an representable method.....

 

but let's say  system.assertEquals(refs[0].OwnerId,testUsers[0].Id)is throwing the error "Error: System.AssertException: Assertion Failed: Expected: null, Actual: 00580000001k6g1AAAClass.testReferralAssignOwner.test: line 11, column 1 Test Class"

 

It simply means that when you are trying to assert the equality of refs[0].OwnerId to OwnerId,testUsers[0].Id the first part i.e. refs[0].OwnerId OwnerId,testUsers[0].Id is returning 00580000001k6g1AAA and hence the assert is failing.

 

I would suggest you to check as why refs[0].OwnerId is null?? My guess is that  the refs isnt able to get the new ownerId after you insert the list as nowhere the list is refreshed....though it is inserted there is no way it can get the ownerId of each Referral__c as it was never refreshed

 

try something like

 

refs = [select ownerId, Client_name__c from Refrral__c where Client_Name__c=a.id and Phone__c='12345' and Assigned__c in (testUsers[0].Id,testUsers[0].Id)];

 

Hope it helps.