You need to sign in to do that
Don't have an account?
Anand@SAAS
Apex batch test method issues
Have a test method for an apex batch and for some reason it is not calling the "Start()" or "Execute()" when i run the tests. If I run the apex batch via execute anonyomous the apex batch runs as expected. Here's my test method:
start():
global Database.QueryLocator start(Database.BatchableContext BC){ ALMLogUtils.log(CLASSNAME,'start() called !!!!'); .... .. }
testMethod:
public static testmethod void testActionAlertBatch(){ TestDataHelper testData = new TestDataHelper(); String acctNbr = '123456'; User usr = testData.createLeaderUser(acctNbr); usr.Action_Alert_Enabled__c=true; usr.Action_Alert_1__c='Orders Not submitted'; usr.Action_Alert_Frequency__c='Daily'; update usr; List<Leader_Downline_Summary__c> ldrData = testData.createLdrSmryData(usr.MRKT_ID_ACCT_NR_KEY__c,usr.Id); Test.startTest(); ActionAlertBatch alertBatch = new ActionAlertBatch(testData.market,System.now()); Database.executeBatch(alertBatch,200); List<Action_Alert__c> alerts = [select Id from Action_Alert__c where OwnerId=:usr.Id]; System.assert(alerts.size()==1); System.assert(alerts[0].Type__c=='Orders Not submitted'); }
Logs when running the test method:
15:2:28.189 (2083121000)|CONSTRUCTOR_EXIT|[140,33]|<Constructor>(SOBJECT:Market__c, Datetime) 15:2:28.189 (2083193000)|STATEMENT_EXECUTE|[141,3]|Database.executeBatch(ActionAlertBatch, Integer) 15:2:28.189 (2083324000)|METHOD_ENTRY|[141,3]|Database.executeBatch(ActionAlertBatch, Integer) 15:2:28.290 (2184134000)|METHOD_EXIT|[141,3]|Database.executeBatch(ActionAlertBatch, Integer) 15:2:28.290 (2184217000)|STATEMENT_EXECUTE|[142,3]|DeclareVar: LIST<Action_Alert__c> alerts 15:2:28.290 (2184250000)|SOQL_EXECUTE_BEGIN|[142,34]|Aggregations:0|select Id from Action_Alert__c where OwnerId=:usr.Id 15:2:28.320 (2214411000)|SOQL_EXECUTE_END|[142,34]|Rows:0 15:2:28.320 (2214499000)|HEAP_ALLOCATE|[142,34]|Bytes:4 15:2:28.320 (2214550000)|HEAP_ALLOCATE|[142,34]|Bytes:4 15:2:28.320 (2214633000)|STATEMENT_EXECUTE|[143,3]|System.assert(Boolean) 15:2:28.320 (2214751000)|METHOD_ENTRY|[143,3]|System.assert(Boolean) 15:2:28.321 (2214808000)|METHOD_ENTRY|[143,17]|LIST<Action_Alert__c>.size() 15:2:28.321 (2214838000)|METHOD_EXIT|[143,17]|LIST<Action_Alert__c>.size() 15:2:28.321 (2214885000)|EXCEPTION_THROWN|[143,3]|System.AssertException: Assertion Failed
Not sure what I'm missing.
Never mind. Had to put "Test.stopTest()" immediately after the database.executeBatch(); Can't beleive I forgot that.
All Answers
Never mind. Had to put "Test.stopTest()" immediately after the database.executeBatch(); Can't beleive I forgot that.
Hello Anand, please contact me with your full resume and contact details at ramavataar@yahoo.com in case you are interested in good opportunities in Top MNC.
Regards
Ram