2

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;

    }

}
1
  • You need to write the test code and assertions inside a test class/method, not in the actual class. Commented Jan 27, 2016 at 5:20

1 Answer 1

3

You should google articles before posting anything here.

Have you looked at this article? https://developer.salesforce.com/forums/?id=906F00000008x42IAA

Anyways, here are your asserts:

System.assert(c==10);
System.assertEquals(a,10);
System.assertNotEquals(b,10);
3
  • I declare this values are these right values? System.assertequals(30,c); System.assertNotEquals(20,c);
    – Bonny
    Commented Jan 27, 2016 at 5:22
  • Why don't you give them a try in your code? You will get a better understanding. And yes they are correct. Commented Jan 27, 2016 at 5:25
  • This should be System.assertEquals(10, a); and same for NotEquals. expected, then actual. Commented Jan 27, 2016 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .