4

バッチプロセスの実装を試みています。これをテストする方法について、いくつかのヘルプ/ガイダンスが必要です。ここで行っているのは、デバッグログに商談名を表示することだけです。しかし、Apexテスト実行でテストクラスも含まれるscheduledBatchableクラスを実行すると。Opp_BatchProcessのデバッグステートメントが表示されません。私が間違っているのは何ですか?

これが私が持っているコードです

global class Opp_BatchProcess implements Database.Batchable < sObject >
{
    globalDatabase.QueryLocator start(Database.BatchableContextBC)
    {
        system.debug('Insidestart');
        returnDatabase.getQueryLocator('select name,id from opportunity');
    }

    global void execute(Database.BatchableContext BC, List <sObject> batch)
    {
        for (Sobject s : batch)
        {
            opportunity o = (opportunity)s;
            system.debug('Opp name is' + o.name);
        }
    }

    global void finish(Database.BatchableContext BC) {}
}

スケジュール可能なクラスもあります

global class scheduledBatchable implements Schedulable
{
    global void execute(SchedulableContext sc)
    {
        Opp_BatchProcess b = new Opp_BatchProcess();
        ID myBatchJobID = database.executebatch(b);
    }

    public static testMethod void testscheduleMerge()
    {
        Test.startTest();
        scheduledBatchable s8 = new scheduledBatchable();
        string sch = '0 0 * * 1-12 ? *';
        system.schedule('Process Trans 1', sch, s8);
        Test.stopTest();
    }
}
4

1 に答える 1

4

testmethodはSchedulableクラスのみをテストしているようです。Batchableクラスもテストする必要があります。

これを試して:

global class scheduledBatchable implements Schedulable
{
    global void execute(SchedulableContext sc)
    {
        Opp_BatchProcess b = new Opp_BatchProcess();
        ID myBatchJobID = database.executebatch(b);
    }

    public static testMethod void testscheduleMerge()
    {
        Test.startTest();
        scheduledBatchable s8 = new scheduledBatchable();
        string sch = '0 0 * * 1-12 ? *';
        system.schedule('Process Trans 1', sch, s8);
        Test.stopTest();
    }

    public static testMethod void testBatchMerge()
    {
        Test.startTest();
        Opp_BatchProcess b = new Opp_BatchProcess();
        ID myBatchJobID = database.executebatch(b);
        Test.stopTest();
    }
}
于 2012-04-09T21:02:52.543 に答える