LoginSignup
1
0

More than 3 years have passed since last update.

Apex Specialist Super Badge 復習[Challenge 6]

Last updated at Posted at 2019-09-16

要件

  • WarehouseSyncScheduleクラスのカバレッジを100%にする。

記載はないが、WarehouseSyncScheduleが呼び出すWarehouseCalloutServiceは外部にコールアウトするのでMockをセットしておく。

Schedulableクラスのテスト

  • どんな日時を指定しても、テスト内ではTest.stopTest()が呼び出されたタイミングで即時実行される。
    • CRON式が適正である必要はある(適当な数字を入れるとテストに失敗する)

参考
Apex スケジューラを使用したジョブのスケジュール 単元 | Salesforce Trailhead

コード
@isTest public class WarehouseSyncScheduleTest {
    public static String CRON_EXP = '0 0 13 * * ? 2022';
    @isTest static void testWarehouseSyncSchedule(){
        Test.setMock(HttpCalloutMock.class,new WarehouseCalloutServiceMock());
        Test.startTest();
        String jobId=System.schedule('test job', CRON_EXP, new WarehouseSyncSchedule());
        Test.stopTest();
    }
}

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0