You need to sign in to do that
Don't have an account?
Solution Archive
Basic test class
Hello,
I have a very basic class and i need to write test class for the same. Can anyone help me understand how to write a test class for this basic getter method in my class.
public with sharing class LinksForContacts { Public List<Contact> getAllLinks(){ List<Contact> theLinks = [Select Title,Link_to_this_Idea__c from Contact]; return theLinks; } }
Thanks a lot!!!!!!!!!!!
It should just be as simple as instantiating the class, executing the getter and asserting you get some response. Something like:
I'm duty bound to point out that the query includes all contacts in the system, so if you have large volumes of data you may hit problems.
All Answers
It should just be as simple as instantiating the class, executing the getter and asserting you get some response. Something like:
I'm duty bound to point out that the query includes all contacts in the system, so if you have large volumes of data you may hit problems.
Hi,
Try below code.
Hope it helps.
Regards,
Devendra S
I guess Bob, Devendra and I were working in parallel... My solution also includes test.startTest() and test.stopTest() to set up the testing limit context:
This article is a great resource for writing test methods - http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
Cheers,
Pat
Hello All,
Thanks you so much to all three of you for clear explanation on testing the getter method.