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
SaaspertSaaspert 

Apex test method results showing wrong message on assertion failure

System.AssertException: Assertion Failed: Expected: 9, Actual: 10

 

I have assert statement system.assertequals(mapCntr.cmapSegments.size(),10);

the cmapsegments is returning 9 elemetns and I put 10 to fail the assertion , it does but with wrong expected and actual numbers.

 

org type: sandbox

Best Answer chosen by Admin (Salesforce Developers) 
kyle.tkyle.t

Your code is saying to expect whatever the size of mapCntr.cmapSegments.size() returns, and the actual number is 10.

 

Just reverse the two in tehe call: system.assertequals(10,mapCntr.cmapSegments.size());

All Answers

hisrinuhisrinu

Assertion will work by comparing two parameters in that method, due to this you are getting the exception... I dont know exactly the order which one will it take it as Expected and Actual, even documentation also

 

Documentation

Asserts that the first two arguments, x and y are the same. If they are not, a runtime exception is thrown with the optional third
Any data type argument, opt_msg as part of its message.

kyle.tkyle.t

Your code is saying to expect whatever the size of mapCntr.cmapSegments.size() returns, and the actual number is 10.

 

Just reverse the two in tehe call: system.assertequals(10,mapCntr.cmapSegments.size());

This was selected as the best answer
SaaspertSaaspert

got it, the order of parameters determines what was expected and what was the actual. good one. thanks