You need to sign in to do that
Don't have an account?
need test class
hi
am very new to test class plz help for the apex class for test class
//Class for User(Contact) Authentication
public class Cls_ContactAuthentication {
public String Username{get; set;}
public String password{get; set;}
public ID ContactID;
public ID UserID;
public Boolean LoginFlag{get; set;}
public List<Contact> contacts;
public Session__c session;
public CLS_ContactAuthentication (){
}
public PageReference Login(){
contacts= new List<Contact>();
session = new Session__c();
try{
contacts= [Select
id,username__c,password__c
from
Contact
where
username__c=:Username
AND
password__c=:password
];
System.debug('#####'+contacts);
}Catch(Exception e){
System.debug(e);
}
if(contacts.size() > 0){
for(Contact a : contacts){
UserID = a.ID;
session.Name = a.id;
}
upsert session;
LoginFlag = false;
if(Username=='' || Password=='')
{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.severity.FATAL, 'Username or Password is missing.......');
ApexPages.addmessage(myMsg);
return new PageReference('/apex/VF_ContactAuthentication');
}
else
{
PageReference page = new PageReference('/apex/VF_ContactHomePage');
page.getParameters().put('ID',UserID);
page.setRedirect(true);
return page;
}
}else{
LoginFlag = true;
return null;
}
}
}
thanks to all
Coverage -> 80 %
@isTest(SeeAllData=true)
private class TestCLS_ContactAuthentication
{
static testMethod void TestCLS_ContactAuthentication()
{
boolean LoginFlag = true;
CLS_ContactAuthentication ca = new CLS_ContactAuthentication();
ca.Login();
}
}