I am stuck in the test class for the Transaction Finalizer class. Every time when we create an exception for Queueable class then Finalizer class executing and then the test class throws the error on the test method and also not handled by try catch.
Below is my Queueable class Sample code:
public class QueueableClass implements Queueable {
public void execute (QueueableContext context) {
QueueableFinalizer finalizer = new QueueableFinalizer();
System.attachFinalizer(finalizer);
// Below code will failed Queueable because of System.LimitException: Too many DML
// statements: 151 And then Finalizer class will be Executes.
if(Test.isRunningTest()){
while (true) { // results in limit error
Account a = new Account();
a.Name = 'Account-Number-';
insert a;
}
}
}
Below is my Finalizer class Sample code:
public class QueueableFinalizer implements Finalizer{
public void execute(FinalizerContext ctx) {
// here we rerun the Queueable by using the system.Queueable
}
}
Below is my Test class Sample code for Finalizer:
public static testMethod void testToFailQueueable() {
test.startTest();
try{
System.enqueueJob(new QueueableClass ()); // here Too many DML Statement Error Occur.
}catch(Exception e){
}
test.stopTest();
}
Please suggest to me how to implement the test class for Finalizer. Thank you!
testMethod
is deprecated, replaced years ago by@isTest
.