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
Abhishek Kumar 149Abhishek Kumar 149 

what is difference between system.assert() and system.assertEqual().

Charisse de BelenCharisse de Belen
System.assert(condition, message) accepts two parameters. The first parameter is the condition you want to check. The second parameter (optional) is the message you want to display if the condition resolves to false.

System.assertEqual(expected, actual, message) accepts three parameters. The first parameter is the value you are expecting. The second parameter is what the value actually resolves to. The third parameter (optional) is the message you want to display if parameter two does not equal parameter one.

Here are some examples:
Integer a = 2, b = 3;

System.assert(a > b, a + ' is not greater than ' + b);
// Assertion Failed: 2 is not greater than 3

System.assert(b > a, b + ' is not greater than ' + a);
// Assertion Succeeds

System.assertEquals(2, a, a + ' is not equal to 2');
// Assertion Succeeds

System.assertEquals(2, b, b + ' is not equal to 2');
// Assertion Failed: 3 is not equal to 2: Expected: 2, Actual: 3

 
Charisse de BelenCharisse de Belen
Hello Abhishek Kumar,

If my answer helped you, please consider marking it as the Best Answer so this question can be marked as Solved. Thank you.