0
public class importDataFromCSVController {
public static blob csvFile{get;set;}
    public static String csvAsString{get;set;}
    public static string[] csvFileLines{get;set;}
   
    public static list<Raw_Data__c> datalist = new list<raw_data__c>();
   
    public static list<Raw_data__c> getdatalist(){
        return datalist;
    }
   
   
    public static void import_Raw_Data()
    { datalist.clear();
        csvAsString = csvFile.toString();
        csvFileLines = csvAsString.split('\n');
       
        for(integer i=0;i<csvFileLines.size();i++)
        {
            raw_data__c obj = new raw_data__C();
             string[] csvRecordData = csvFileLines[i].split(',');
            obj.name = csvRecordData[0];
           
            obj.Salary__c = Double.valueOf(string.valueOf(csvRecordData[1]));
            if(obj !=null)
            {
            datalist.add(obj);
            }
          }
}
}

@isTest
public class TestClass_Task_8 {

    static String str = 'Name,Salary__c';
   
   public static String[] csvFileLines;
    public static Blob csvFileBody;

    static testmethod void testfileupload(){
        Test.startTest();      
        csvFileBody = Blob.valueOf(str);
        String csvAsString = csvFileBody.toString();
        csvFileLines = csvAsString.split('\n');

        TestClass_Task_8 importData = new TestClass_Task_8();
        importData.csvFileBody = csvFileBody;
        importData.import_Raw_Data();
        Test.stopTest();
    }

    static testmethod void testfileuploadNegative(){
        Test.startTest();      
        csvFileBody = Blob.valueOf(str);
        String csvAsString = csvFileBody.toString();
        csvFileLines = csvAsString.split('\n');

        TestClass_Task_8 importData = new TestClass_Task_8();
        importData.import_Raw_Data();
        Test.stopTest();
    }

   
}

enter image description here

  • 2
    Kinda hard to help if you don't tell us what the error is. edit your question to include more details. – Derek F Jul 9 at 11:42
  • Yes I uploaded a image of error that I'm faced in test class – Shalini goyal Jul 9 at 13:44
  • Why are any of these items marked static? – David Reed Jul 9 at 14:47
2

These are compilation errors. The system is telling you that it doesn't understand your code. The line numbers tell you were the problematic code is, although sometimes the actual error occurs in another spot. For example, the "Method does not exist..." errors occur on the two lines that contain importData.import_Raw_Data();, but the actual problem is that your importData object in that line is the wrong type of object. In both test methods, you have this line:

TestClass_Task_8 importData = new TestClass_Task_8();

You are creating a new instance of your test class, NOT the class you need to test (importDataFromCSVController). Change those lines to:

TestClass_Task_8 importData = new importDataFromCSVController();

Your first test method also contains the line:

importData.csvFileBody = csvFileBody;

However, importDataFromCSVController doesn't have a public csvFileBody property/variable. I suspect that line should be:

importData.csvFileLines = csvFileLines;
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.