You need to sign in to do that
Don't have an account?
Andrew Hoban 6
Test Class for VF Page
Hi all,
I have created a test class for a VF page but not sure if it is working. The Apex class we are trying to test is shown below: Thanks
Class
Test Class
I have created a test class for a VF page but not sure if it is working. The Apex class we are trying to test is shown below: Thanks
Class
public class EvertonUsersLeavers { public List<Everton_Users__c> getEvertonUsersLeavers() { return [SELECT Name, Leaver_Date__c, Email_Address__c FROM Everton_Users__c WHERE Leaver_Date__c >= TODAY]; } }
Test Class
@isTest public class EvertonUsersLeaversTest{ public static testMethod void EvertonUsersLeavers(){ Everton_Users__c USER = new Everton_Users__c( Name = 'Test Name', Leaver_Date__c = Date.newInstance(2015 , 07 ,15), Email_Address__c = 'test@evertonfc.com' ); insert USER; } }
@isTest
public class EvertonUsersLeaversTest{
public static testMethod void EvertonUsersLeavers(){
Test.startTest()
Everton_Users__c USER = new Everton_Users__c(
Name = 'Test Name',
Leaver_Date__c = Date.newInstance(2015 , 07 ,15),
Email_Address__c = 'test@evertonfc.com'
);
insert USER;
EvertonUsersLeavers evntuserObj= new EvertonUsersLeavers()
System.assertNotEquals(evntuserObj.getEvertonUsersLeavers(),null);
System.assert(evntuserObj.getEvertonUsersLeavers().size()>0)
Test.stopTest();
}
}
Best Regards,
-Vivek
All Answers
You havent created class intance in test class.
Try this.
@isTest public class EvertonUsersLeaversTest
{ public static testMethod void EvertonUsersLeavers()
{ Everton_Users__c USER = new Everton_Users__c( Name = 'Test Name', Leaver_Date__c = Date.newInstance(2015 , 07 ,15), Email_Address__c = 'test@evertonfc.com' );
insert USER; }
EvertonUsersLeavers EvertonUsersLeaversObj= new EvertonUsersLeavers();
EvertonUsersLeaversObj.getEvertonUsersLeavers();
}
Thanks
ShaT
Please try below code and let know if it helps.
@isTest
public class EvertonUsersLeaversTest{
public static testMethod void EvertonUsersLeavers(){
Test.startTest()
Everton_Users__c USER = new Everton_Users__c(
Name = 'Test Name',
Leaver_Date__c = Date.newInstance(2015 , 07 ,15),
Email_Address__c = 'test@evertonfc.com'
);
insert USER;
EvertonUsersLeavers evntuserObj= new EvertonUsersLeavers()
System.assertNotEquals(EvertonUsersLeavers.getEvertonUsersLeavers(),null);
System.assert(EvertonUsersLeavers.getEvertonUsersLeavers().size()>0)
Test.stopTest();
}
}
Please mark the best answer.
Best Regards,
-Vivek
EvertonUsersLeaversObj.getEvertonUsersLeavers();
Thank you
@isTest
public class EvertonUsersLeaversTest{
public static testMethod void EvertonUsersLeavers(){
Test.startTest()
Everton_Users__c USER = new Everton_Users__c(
Name = 'Test Name',
Leaver_Date__c = Date.newInstance(2015 , 07 ,15),
Email_Address__c = 'test@evertonfc.com'
);
insert USER;
EvertonUsersLeavers evntuserObj= new EvertonUsersLeavers()
System.assertNotEquals(evntuserObj.getEvertonUsersLeavers(),null);
System.assert(evntuserObj.getEvertonUsersLeavers().size()>0)
Test.stopTest();
}
}
Best Regards,
-Vivek