2013-03-27 17 views
1

我測試我的應用程序。它給我錯誤System.UnexpectedException:在測試方法中不能調用一個以上的executeBatch

System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation. 

我試圖在這個程序是基於谷歌日曆Api.thats調用批處理頂點類爲什麼。但我面臨的上述錯誤無法解析JSON響應。

@isTest public class TestBatchCleanGCalendars { 

    static testMethod void testBatchJob() { 

     GoogleTestHelper.createfullGSettings(10); 
     GoogleTestHelper.createCampaigns(); 

     List<Campaign> campaigns = [Select Id, Name from Campaign]; 

     system.assertEquals(5,campaigns.size()); 

     GoogleTestHelper.createTestCalendars(); 

     GCalendarUtil.testResponse = GoogleTestHelper.returnGCalendarResp(); 
      BatchCleanGCalendars bJob = new BatchCleanGCalendars('Select Id, Name, CalendarId__c,CalendarQuery__c,FieldToDisplay__c from CalendarSettings__c'); 

     bJob.testResponse = '{' 
+' "kind": "calendar#events",' 
+' "summary": "Saarthak",' 
+' "description": "",' 
+' "updated": "2013-03-26T10:17:05.354Z",' 
+' "timeZone": "Asia/Calcutta",' 
+' "accessRole": "owner",' 
+' "items": [' 
+' {' +' "kind": "calendar#event",' +' "id": "c3gmu1me12tmujuifgmbrr33rc",' +' "status": "confirmed",' 
+ ' "htmlLink": "https://www.google.com/calendar/event?eid=YzNnbXUxbWUxMnRtdWp1aWZnbWJycjMzcmMgamg5NWRyMDhpNDdwZ3RkMzFmMzQ5Z25uZmdAZw",' 
+' "created": "2013-03-26T10:17:03.000Z",' +' "updated": "2013-03-26T10:17:03.552Z",' +' "summary": "GC Product Webinar - Jan 7, 2002",' +' "description": "null",' +' "creator": {' +' "email": "[email protected]"' +' },' +' "organizer": {' 
+' "email": "[email protected]",' +' "displayName": "Saarthak",' +' "self": true' +' },' +' "start": {' +' "date": "2006-09-04"' +' },' +' "end": {' +' "date": "2006-09-04"' +' },' +' "iCalUID": "[email protected]",' +' "sequence": 0,' +' "reminders": {' +' "useDefault": true' +' }' +' },' +' {' +' "kind": "calendar#event",' +' "id": "6se2vm8guhbh2tekc7scnpcudc",' 
+' "status": "confirmed",' +' "htmlLink": "https://www.google.com/calendar/event?eid=NnNlMnZtOGd1aGJoMnRla2M3c2NucGN1ZGMgamg5NWRyMDhpNDdwZ3RkMzFmMzQ5Z25uZmdAZw",' 
+' "created": "2013-03-26T10:17:04.000Z",' +' "updated": "2013-03-26T10:17:04.096Z",' +' "summary": "User Conference - Jun 17-19, 2002",' +' "description": "null",' +' "creator": {' +' "email": "[email protected]"' +' },' +' "organizer": {' 
+' "email": "[email protected]",' +' "displayName": "Saarthak",' +' "self": true' +' },' +' "start": {' +' "date": "2007-02-12"' +' },' +' "end": {' +' "date": "2007-02-14"' +' },' +' "iCalUID": "[email protected]",' +' "sequence": 0,' +' "reminders": {' +' "useDefault": true' +' }' +' },' +' {' +' "kind": "calendar#event",' +' "id": "8of1l1ffqbfmm582und3q42k10",' 
+' "status": "confirmed",' +' "htmlLink": "https://www.google.com/calendar/event?eid=OG9mMWwxZmZxYmZtbTU4MnVuZDNxNDJrMTAgamg5NWRyMDhpNDdwZ3RkMzFmMzQ5Z25uZmdAZw",' 
+' "created": "2013-03-26T10:17:04.000Z",' +' "updated": "2013-03-26T10:17:04.707Z",' +' "summary": "DM Campaign to Top Customers - Nov 12-23, 2001",' +' "description": "null",' +' "creator": {' +' "email": "[email protected]"' +' },' 
+'"organizer": {' +' "email": "[email protected]",' +' "displayName": "Saarthak",' +' "self": true' +' },' +' "start": {' +' "date": "2006-07-10"' +' },' +' "end": {' +' "date": "2006-07-21"' +' },' +' "iCalUID": "[email protected]",' +' "sequence": 0,' +' "reminders": {' +' "useDefault": true' +' }' +' }' 
+' ]' 
+',"nextPageToken": "CigKGjFhaW9oc25nZTFhZzBxYTY4bjZhOGlrdG5nGAEggICA0arZqecT"' 
+'}'; 

bJob.testResponse1 = '{' 
+' "kind": "calendar#events",' 
+' "summary": "Saarthak",' 
+' "description": "",' 
+' "updated": "2013-03-26T10:17:05.354Z",' 
+' "timeZone": "Asia/Calcutta",' 
+' "accessRole": "owner",' 
+' "items": [' 
+' {' +' "kind": "calendar#event",' +' "id": "c3gmu1me12tmujuifgmbrr33rc",' +' "status": "confirmed",' 
+ ' "htmlLink": "https://www.google.com/calendar/event?eid=YzNnbXUxbWUxMnRtdWp1aWZnbWJycjMzcmMgamg5NWRyMDhpNDdwZ3RkMzFmMzQ5Z25uZmdAZw",' 
+' "created": "2013-03-26T10:17:03.000Z",' +' "updated": "2013-03-26T10:17:03.552Z",' +' "summary": "GC Product Webinar - Jan 7, 2002",' +' "description": "null",' +' "creator": {' +' "email": "[email protected]"' +' },' +' "organizer": {' 
+' "email": "[email protected]",' +' "displayName": "Saarthak",' +' "self": true' +' },' +' "start": {' +' "date": "2006-09-04"' +' },' +' "end": {' +' "date": "2006-09-04"' +' },' +' "iCalUID": "[email protected]",' +' "sequence": 0,' +' "reminders": {' +' "useDefault": true' +' }' +' },' +' {' +' "kind": "calendar#event",' +' "id": "6se2vm8guhbh2tekc7scnpcudc",' 
+' "status": "confirmed",' +' "htmlLink": "https://www.google.com/calendar/event?eid=NnNlMnZtOGd1aGJoMnRla2M3c2NucGN1ZGMgamg5NWRyMDhpNDdwZ3RkMzFmMzQ5Z25uZmdAZw",' 
+' "created": "2013-03-26T10:17:04.000Z",' +' "updated": "2013-03-26T10:17:04.096Z",' +' "summary": "User Conference - Jun 17-19, 2002",' +' "description": "null",' +' "creator": {' +' "email": "[email protected]"' +' },' +' "organizer": {' 
+' "email": "[email protected]",' +' "displayName": "Saarthak",' +' "self": true' +' },' +' "start": {' +' "date": "2007-02-12"' +' },' +' "end": {' +' "date": "2007-02-14"' +' },' +' "iCalUID": "[email protected]",' +' "sequence": 0,' +' "reminders": {' +' "useDefault": true' +' }' +' },' +' {' +' "kind": "calendar#event",' +' "id": "8of1l1ffqbfmm582und3q42k10",' 
+' "status": "confirmed",' +' "htmlLink": "https://www.google.com/calendar/event?eid=OG9mMWwxZmZxYmZtbTU4MnVuZDNxNDJrMTAgamg5NWRyMDhpNDdwZ3RkMzFmMzQ5Z25uZmdAZw",' 
+' "created": "2013-03-26T10:17:04.000Z",' +' "updated": "2013-03-26T10:17:04.707Z",' +' "summary": "DM Campaign to Top Customers - Nov 12-23, 2001",' +' "description": "null",' +' "creator": {' +' "email": "[email protected]"' +' },' 
+'"organizer": {' +' "email": "[email protected]",' +' "displayName": "Saarthak",' +' "self": true' +' },' +' "start": {' +' "date": "2006-07-10"' +' },' +' "end": {' +' "date": "2006-07-21"' +' },' +' "iCalUID": "[email protected]",' +' "sequence": 0,' +' "reminders": {' +' "useDefault": true' +' }' +' }' 
+' ]' 
+'}'; 
     Test.StartTest(); 

     System.assertEquals(2,[Select count() from CalendarSettings__c ]); 

       DataBase.executeBatch(bJob); 


     Test.StopTest(); 


    } 

在完成方法完成批量請求後,我打電話多了一個批處理class.can任何一個請點我爲什麼我的時候我在TestMethod的調用一個批次類得到這個錯誤?請幫助一下

回答

2

雖然您可以從另一個批次類調用批次類,但您只允許從測試類中調用一個批次類。因此你正面臨着這個錯誤。

替代方法是檢查調用批處理類的完成方法,無論您處於測試上下文還是常規上下文中。你可以使用Test.isRunningTest()來做到這一點。

相關問題