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
Meenakshi sinhaMeenakshi sinha 

how to write test class


Hello
Pls guide me in writing test class for the VF page.
​<apex:page standardController="Account"
           recordSetVar="accounts"
           tabStyle="Account"
           sidebar="false">
 
 <apex:pageBlock title="">
 
   <apex:repeat value="{!accounts}" var="a">
   
  <apex:pageBlockSection title="{!a.Name}"/>
 
  <apex:relatedList list="Contacts"
                    subject="{!a.ID}"
                    id="relatedlist1"
                    title="Contact Info"/>
 
 <apex:relatedList list="Opportunities"
                    subject="{!a.ID}"
                    id="relatedlist2"
                    title="Opportunity Info"/>
                  
</apex:repeat>
 </apex:pageBlock>
           
 
</apex:page>

@istest(SeeAllData=False)
private class MyCls_Test
{
    private static testmethod void testdata()
   {
          Profile p=[Select Id  from profile where name ='System Administrator'];
        
          User u=new User(ProfileId = p.Id, username = 'testmail@org.com', email = 'testuser@gmail.com',
        
                                        EmailEncodingKey = 'UTF-8' , LocaleSidKey = 'en_US',
                                      
                                        LanguageLocaleKey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                                      
                                        alias='cspu',  lastname='lastname');
                
             System.RunAs(u)
            {
         }
}
Thanks
meenakshi​​​​
Best Answer chosen by Meenakshi sinha
Amit Chaudhary 8Amit Chaudhary 8
Hi Meenakshi sinha,

You dnt need to write any test class for above VF page because above VF nt contain any apex class. We need to write test class for apex class and trigger only.

Please let us know if this will help u

Thanks
Amit Chaudhary
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Hi Meenakshi sinha,

You dnt need to write any test class for above VF page because above VF nt contain any apex class. We need to write test class for apex class and trigger only.

Please let us know if this will help u

Thanks
Amit Chaudhary
 
This was selected as the best answer
Meenakshi sinhaMeenakshi sinha
Thanks