You need to sign in to do that
Don't have an account?

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<User> testUsers = [select id from user where isactive = true limit 2]; Account a = new Account(Name='test'); insert a; List<Referral__c> refs = new List<Referral__c>(); 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!
Awesome, thanks you are the best! Here is the final test class that works for 100% coverage:
All Answers
If you switch the parameters you should have Expected: ID and Actual: Null.
To resolve you should query the DB again including the OwnerId field:
Thanks for the quick reply!
I am getting this error once I add the code:
Here is the code:
Sorry, my fault! Try this! ;)
Awesome, thanks you are the best! Here is the final test class that works for 100% coverage: