You need to sign in to do that
Don't have an account?
mukesh gupta 8
testMethod
Hi Experts,
I am new in salesforce and little bit confusse for testMethod for this class, How i can use testMethod for below class so that i can get 75% code coverage, and get the current records form the "getTodaysMileageRecords()" function that's returning the list.
@isTest
public class MileageExtension {
private final Mileage__c mileageObj;
public MileageExtension(ApexPages.StandardController controller) {
this.mileageObj = (Mileage__c)controller.getRecord();
}
public Mileage__c[] getTodaysMileageRecords() {
String createdbyId = UserInfo.getUserId();
Mileage__c[] mileageList = [SELECT name, miles__c
FROM Mileage__c
WHERE Date__c = TODAY
AND createdbyid = :createdbyId];
return mileageList;
}
}
Waiting for possitive reply
Many Thanks
Mukesh gupta
I am new in salesforce and little bit confusse for testMethod for this class, How i can use testMethod for below class so that i can get 75% code coverage, and get the current records form the "getTodaysMileageRecords()" function that's returning the list.
@isTest
public class MileageExtension {
private final Mileage__c mileageObj;
public MileageExtension(ApexPages.StandardController controller) {
this.mileageObj = (Mileage__c)controller.getRecord();
}
public Mileage__c[] getTodaysMileageRecords() {
String createdbyId = UserInfo.getUserId();
Mileage__c[] mileageList = [SELECT name, miles__c
FROM Mileage__c
WHERE Date__c = TODAY
AND createdbyid = :createdbyId];
return mileageList;
}
}
Waiting for possitive reply
Many Thanks
Mukesh gupta
your class, without @isTest annotation: test method should be (it's and example, not complete test method :) ):
I have implement the my class according your method but got error Compilation error: Constructor not defined: [MileageExtension].<Constructor>()
@isTest
public class ExtensionTestMethod {
public static testMethod void ExtensionTestMethod() {
PageReference pageRef = Page.MyMileagePage;
Test.setCurrentPage(pageRef);
///below line show the error for Compilation error: Constructor not defined: [MileageExtension].<Constructor>()///////////////
MileageExtension controller = new MileageExtension();
Mileage__c[] mileageTest = controller.getTodaysMileageRecords();
System.assert(/* here you put assertion to make sure your method is working correctly*/);
}
}
Many Thanks
Mukesh