You need to sign in to do that
Don't have an account?
bonny mankotia
How To Check Different Assert Methods in this code?
public with sharing class AssertEx
{
public integer sum()
{
integer a =10;
integer b =20;
integer c;
c=a+b;
system.debug('======'+c);
//system.assert();
//system.assertequals();
//System.assertNotEquals();
return c;
}
}
{
public integer sum()
{
integer a =10;
integer b =20;
integer c;
c=a+b;
system.debug('======'+c);
//system.assert();
//system.assertequals();
//System.assertNotEquals();
return c;
}
}
integer a =10;
integer b =20;
integer c;
c=a+b;
system.debug('======'+c);
system.assert(c!=(a+b),'Its an Error');
system.assertequals(c,(a-b),'Sum Not Equals');
System.assertNotEquals(c,(a+b),'Sum Equals');
System.assert(condition, msg)
Asserts that the specified condition is true. If it is not, a fatal error is returned that causes code execution to halt.
eg:system.assert(c!=(a+b),'Its an Error');
System.assertEquals(expected, actual, msg)
Asserts that the first two arguments are the same. If they are not, a fatal error is returned that causes code execution to halt.
eg:system.assertequals(c,(a-b),'Sum Not Equals');
System.assertNotEquals(expected, actual, msg)
Asserts that the first two arguments are different. If they are the same, a fatal error is returned that causes code execution to halt.
eg:System.assertNotEquals(c,(a+b),'Sum Equals');
All Answers
integer a =10;
integer b =20;
integer c;
c=a+b;
system.debug('======'+c);
system.assert(c!=(a+b),'Its an Error');
system.assertequals(c,(a-b),'Sum Not Equals');
System.assertNotEquals(c,(a+b),'Sum Equals');
System.assert(condition, msg)
Asserts that the specified condition is true. If it is not, a fatal error is returned that causes code execution to halt.
eg:system.assert(c!=(a+b),'Its an Error');
System.assertEquals(expected, actual, msg)
Asserts that the first two arguments are the same. If they are not, a fatal error is returned that causes code execution to halt.
eg:system.assertequals(c,(a-b),'Sum Not Equals');
System.assertNotEquals(expected, actual, msg)
Asserts that the first two arguments are different. If they are the same, a fatal error is returned that causes code execution to halt.
eg:System.assertNotEquals(c,(a+b),'Sum Equals');
you could interchange any of the Assert functions dependent on your logic. Up to you. I find it easier to use AssertEquals as I mostly want to check that a proper number of records have been returned or that something I know about has happened and I'm expecting a certain result etc.
Thanks
Rupal Kumar
Mirketa Software Pvt Ltd
http://mirketa.com/index.html