function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc demo 1sfdc demo 1 

test class did not working ,need test class for constructor with string parameter in batch apex class

Here is the code:

global with sharing class ImportBatch implements Database.Batchable<string>, Database.Stateful{
    
    global final blob dataDocuments;
    
    global ImportBatch (blob data){
        this.dataDocuments=data;
    }
    
    
    global Iterable<string>  start(Database.BatchableContext BC){
        string nameFile=this.dataDocuments.toString();        
        return new CSVIterator(this.dataDocuments.toString(), '\n');
    }
    
    global void execute(Database.BatchableContext BC,List<String> scope){
        
        List<Custom_Object__c> CustomObjectList = new list<Custom_Object__c>();
        for(String row : scope){
            
            List<String> fields = row .split(',');
            
            //Edit from here------------------------------
            Custom_Object__c li=new Custom_Object__c();
            
            li.name =fields[0];                
            li.Field_1__c=fields[1];        
            li.Field_2__c=fields[2];
            //To here-------------------------------------

            CustomObjectList.add(li);
        }
        
        //Insert
        if(CustomObjectList.getSObjectType().getDescribe().isCreateable()){       
            insert CustomObjectList;  
        }
        
    }
    
    global void finish(Database.BatchableContext BC){
        
        // Send an email to the Apex job's submitter notifying of job completion.  
        AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          from AsyncApexJob where Id =:BC.getJobId()];
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {a.CreatedBy.Email};
            mail.setToAddresses(toAddresses);
        mail.setSubject('Import' + a.Status);
        mail.setHTMLBody('Dear User,  <br/> <br/> Your import has finished. During the porcess there were ' + 
                         + a.NumberOfErrors + ' errors.');
        
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        
        
    }        
    
}

Thanks in advance