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
nitinkhunal.ax1786nitinkhunal.ax1786 

i'm trying to write my first test class. plz tell me how to write for this apex class?

public class RegistrationMethod
{
public string fnameI{get; set;}
public string lnameI{get; set;}
public string phoneI{get; set;}
public string emailI{get; set;}

 

public void Register()
{
Candidate__c c=new Candidate__c();
c.First_Name__c=fnameI;
c.Last_Name__c=lnameI;
c.Phone__c=phoneI;
c.Email__c=emailI;
insert c;

}

}

souvik9086souvik9086

Create a test class like this

 

@isTest
public class MyTestClass {
     // Methods for testing 
   @isTest static void test1() {

         Test.starttest();

         RegistrationMethod regCon = new RegistrationMethod();

         Candidate__c c = new Candidate__c();

         c.First_Name__c=fnameI;
         c.Last_Name__c=lnameI;
         c.Phone__c=phoneI;
         c.Email__c=emailI;
         insert c;

regCon.Register();

test.stoptest();

    }

}

 

Note: Create a constructor in your class like

public RegistrationMethod(){

}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks