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
wixxeywixxey 

What is Test code in apex?explain one example

really i am stuck with these apex test codes..

Kindly help ....

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

The test code is used to pragmatically test your code and ensure that everything is working fine as expected.

 

Mostly it is used for deployment(pushing code from one org to another, developer or sandbox to production).
These test classes runs automatically each time you deploy your code, if they fail then it means something in your code is not working or need to be corrected.

 

Test classes - simply tests whether your code will work in destination org or not(It will let you know the status before actually pushing your code).

 

Refer this document for more detail.

All Answers

Rahul SharmaRahul Sharma

The test code is used to pragmatically test your code and ensure that everything is working fine as expected.

 

Mostly it is used for deployment(pushing code from one org to another, developer or sandbox to production).
These test classes runs automatically each time you deploy your code, if they fail then it means something in your code is not working or need to be corrected.

 

Test classes - simply tests whether your code will work in destination org or not(It will let you know the status before actually pushing your code).

 

Refer this document for more detail.

This was selected as the best answer
wixxeywixxey

thnx Rahul for giving your time .. the problem i am facing is i am not able to write test code for my code...  i have problem regarding passing the fake data into the test code.. any suggestion regarding it???

ManjunathManjunath

Hi,

It is very simple. You are suppose to create an instance of the object. The enter in all the required fields for that object. Last step is to insert it.

Follow this link http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm

Regards,