0

I'm trying to test a Queueable class and I'm getting 55% only.. I tried several things but I'm still getting only 55%.

This is the class:

public class SherlockQueueablePolling implements Queueable, Database.AllowsCallouts {

@TestVisible private static Boolean doChainJob = true;
public Boolean switcher;

public SherlockQueueablePolling() {}

public void execute(QueueableContext context) {

    switcher = [SELECT QueueableSwitch__c FROM SherlockQueueable__mdt].QueueableSwitch__c;

    if (doChainJob && switcher) {
        try {
            ScreeningService.getPollingSherlockEngine().processScreeningResults();
        } catch (AsyncException ex) {
            System.debug('The following exception has occurred: ' + ex.getMessage());
        } finally {
            System.enqueueJob(new SherlockQueueablePolling());
        }
    }
  }
}

Test class:

@IsTest
private class SherlockQueueablePollingTest {
static testMethod void testQueueableChainingBehavior() {
    SherlockQueueablePolling.doChainJob = false;

    Test.startTest();
    Queueable myQ = new SherlockQueueablePolling();
    myQ.execute(null);
    Test.stopTest();
    SherlockQueueablePolling firstQueueableJob = new SherlockQueueablePolling();
    firstQueueableJob.execute(null);
    SherlockQueueablePolling secondQueueableJob = new SherlockQueueablePolling();
    secondQueueableJob.execute(null);

   }
}

Any ideas how I can get this done right?

UPDATE: Screenshot with parts that are not covered:

enter image description here

4
  • Can you post screen shot which part of code not covering ?
    – MIX DML
    Feb 21 '19 at 11:38
  • @MIXDML, I added the screenshot. Feb 21 '19 at 11:43
  • Is there a reason you are making doChainJob as false in test class? as its false, it wont enter if block Feb 21 '19 at 11:53
  • It is to avoid the error: System.AsyncException: Maximum stack depth has been reached. The queueable will fire himself over and over... Setting up doChainJob to true in the test will fires the error mentioned above.. Feb 21 '19 at 11:59
0

Just got 88% by changing the test class to this:

@IsTest
private class SherlockQueueablePollingTest {
    static testMethod void testQueueableChainingBehavior() {
    SherlockQueueablePolling.doChainJob = true;
    Test.startTest();
    Queueable myQ = new SherlockQueueablePolling();
    myQ.execute(null);
    SherlockQueueablePolling.doChainJob = false;
    Test.stopTest();

   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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