You need to sign in to do that
Don't have an account?
need code coverage for this test class
hi
i write test class i get only 52%
i have to get 80% code can u any one help me
thanks....
@isTest
public class Test_MemberPortal
{
static testMethod void TestCls_ContactAuthentication()
{
Account testAccount=new Account();
testAccount.Name='rvai';
insert testAccount;
Contact testContact=new Contact();
testContact.lastname='devesh';
testContact.firstName = 'James';
testContact.username__c='test contact1';
testContact.password__c = 'Password123';
testContact.accountid=testAccount.id;
insert testContact;
Cls_ContactAuthentication objCls_ContactAuthentication = new Cls_ContactAuthentication();
objCls_ContactAuthentication.Username = 'User123';
objCls_ContactAuthentication.password = 'Password123';
objCls_ContactAuthentication.Login();
objCls_ContactAuthentication.Username = 'User123NoMatch';
objCls_ContactAuthentication.Login();
}
}
this is my apex 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;
}
}
}
Coverage 80% ->
@isTest(SeeAllData=true)
public class Test_MemberPortal
{
static testMethod void TestCls_ContactAuthentication()
{
CLS_ContactAuthentication1 cls = new CLS_ContactAuthentication1();
cls.Login();
}
}