You need to sign in to do that
Don't have an account?
nitinkhunal.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;
}
}
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