You need to sign in to do that
Don't have an account?

Help with writing a test method
I've built a custom uploader and I'm struggling to write a test method for it. I was hoping some wouldn't mind helping me out. See Code below.
public class Equipment_CSV_FileUploader
{
public PageReference reset() {
return null;
}
public string nameFile{get;set;}
public Blob contentFile{get;set;}
String[] filelines = new String[]{};
List<Equipment__c> accstoupload;
public Pagereference ReadFile()
{
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
accstoupload = new List<Equipment__c>();
for (Integer i=1;i<filelines.size();i++)
{
String[] inputvalues = new String[]{};
inputvalues = filelines[i].split(',');
Equipment__c a = new Equipment__c();
a.Name = inputvalues[0];
a.Receiver_S__c = inputvalues[1];
a.Receiver_Model__c = inputvalues[2];
a.Opportunity__c = ApexPages.currentPage().getParameters().get('oppId');
accstoupload.add(a);
}
try{
insert accstoupload;
}
catch (Exception e)
{
ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template');
ApexPages.addMessage(errormsg);
}
return null ;
}
public List<Equipment__c> getuploadedEquipment()
{
if (accstoupload!= NULL)
if (accstoupload.size() > 0)
return accstoupload;
else
return null;
else
return null;
}
}
This is what I have for a test method so far. I'm at 19% but I really have no idea what I'm doing
@istest
private class Equipment_CSV_FileUploader_TestMethod
{
static testmethod void Equipment_CSV_FileUploader_TestMethod()
{
Equipment_CSV_FileUploader testcls = new Equipment_CSV_FileUploader();
testcls.ReadFile();
testcls.reset();
}
}
Thanks in advance!
Hi
@istest
private class Equipment_CSV_FileUploader_TestMethod
{
static testmethod void Equipment_CSV_FileUploader_TestMethod()
{
Equipment__c eq = new Equipment__c();
insert here the mandatory fields of Equipment__c
insert eq;
Equipment_CSV_FileUploader testcls = new Equipment_CSV_FileUploader();
testcls.ReadFile();
testcls.reset();
eq= testcls.getuploadedEquipment();
}
}
Regards,
Rajesh.