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
goodankit@yahoo.comgoodankit@yahoo.com 

How to use system.assert in test class

NrusinghNrusingh

system.assert is just is used for cheking the functionalities that you are going to do in the test class like insertin or updating any object....
For Example--> Contact objcon = new Contact(LastName= 'Test-Contact-1');

                              insert objcon;

                             system.assert(objcon.Id != null);

 

 

suppose the Contact object not inserted then assert will throw an error so u can say by assert u can get the perfect results what u want....assertEquals also doing almost the same job.....Thanks

Ashish_SFDCAshish_SFDC

Hi Ankit, 

 

These are part of the System methods, 

These are used widely for executing APEX Test classes, where we compare the output with the expected value. When the values are same assertion succeeds. 

Also we use AssertNotEquals when we expect the output to be different where assertion fails if the answers match. 

 

See the detailed description of Assert methods in the article below,

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_system.htm

 

Regards,

Ashish

If your question is answered, please mark this post as solved.