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
Jakson MonteiroJakson Monteiro 

How to get Test Coverage for Database.emptyRecycleBin

I m not able to get the Test Coverage for only Database.emptyRecycleBin in my Test class

Below is my code snippet where i am not able to get coverage in my Apex Class
    global void execute(Database.BatchableContext BC, list<Application__c > scope){     
        delete scope;   
        DataBase.emptyRecycleBin(scope); 
    }

Below is my Test Class:

@isTest(SeeAllData=true)
public class RS_PurgeRecycleBinApplicationTest
{
  static testMethod void RS_PurgeRecycleBin()
  {
   test.StartTest();
   Application__c app=new Application__c();
   app.Application_Status__c='Paper';
   app.GUID__c='1111';
   Insert app;
   
   List <Application__c> delApp=new List<Application__c>([Select Id from Application__c where GUID__c='1111']);
   Delete delapp;
     
     
   test.StopTest();
   
   
    RS_PurgeRecycleBinApplication batchtest=new RS_PurgeRecycleBinApplication();
      Database.executeBatch(batchtest);
      
      
      RS_PurgeRecycleBinApplication schedulebatch=new RS_PurgeRecycleBinApplication();
      String cronExp = '0 15 0 * * ? 2099';
      String jobId = System.schedule('testRS_Scheduled', cronExp, schedulebatch);  
  }
  
  
  }
Amit Chaudhary 8Amit Chaudhary 8
Please try below test class. I hope that will help you
@isTest
public class RS_PurgeRecycleBinApplicationTest
{
	static testMethod void RS_PurgeRecycleBin()
	{
	   Application__c app=new Application__c();
	   app.Application_Status__c='Paper';
	   app.GUID__c='1111';
	   Insert app;

		test.StartTest();
			RS_PurgeRecycleBinApplication batchtest=new RS_PurgeRecycleBinApplication();
			Database.executeBatch(batchtest);
		test.StopTest();
	}
}
NOTE:- Please dnt delete you data inside your test class data as you are deleting data from your batch job itself.
Make sure you Application__c data should be according to you Start Method Query so that your execute method will call