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
manav_mnvmanav_mnv 

Unit Test Mechanism

Hello All

I want to prepare a document on Unit Test mechanism of Apex classes and triggers. Can anybody suggest some links, where i can find good material for this topic.

Thanks
Manav
ManojjenaManojjena
Hi Manav,

Check below links 

https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods  

https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests   

https://developer.salesforce.com/blogs/engineering/2013/04/apex-test-code-segregation.html

http://www.laceysnr.com/2013/04/three-reasons-you-should-write-proper.html

Check below link I have added one comment where you will find some use ful points .

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BBAZIA4   

Below link wil help you how to cover catch block .

https://developer.salesforce.com/forums?id=906F0000000B1x5IAC


1.Tips for standardcontroller 
ApexPages.standradController con=ApexPages.StandradController(Needs to pass the instance of the standard/Custom Object);

2.standardSetcontroller

ApexPages.standradSetController con=ApexPages.StandradSetController(Needs to pass the list of the standard/Custom Object);


Let me know if it helps !

Thanks 
Manoj


 
manav_mnvmanav_mnv
Thanks Manoj :)

Let me study all material, if i have any further questions, will come back to you.
JayantJayant
Check out this recent webinar, its really helpful and every minute is worth it.
You should subscribe to the Salesforce Developers YouTube channel. It has several webinars on Apex Testing from various events like DreamForce etc. which are far more useful and time saving than reading several PDFs and gaining a little.

https://www.youtube.com/watch?v=jDzEEepeLes
Amit Chaudhary 8Amit Chaudhary 8
Single action
Test to verify that a single record produces the correct, expected result.

Bulk actions
Any Apex code, whether a trigger, a class or an extension, may be invoked for 1 to 200 records. You must test not only the single record case, but the bulk cases as well.

Restricted user
Test whether a user with restricted access to the sObjects used in your code sees the expected behavior. That is, whether they can run the code or receive error messages.

Positive behavior
Test to verify that the expected behavior occurs through every expected permutation, that is, that the user filled out everything correctly and did not go past the limits.

Negative behavior
There are likely limits to your applications, such as not being able to add a future date, not being able to specify a negative amount, and so on. You must test for the negative case and verify that the error messages are correctly produced as well as for the positive, within the limits cases.

Test Methods
Apply testMethod or @isTest to methods
      • Demarcates a single self-contained test
      • Signature characteristics:

Please let me know if this will help you.