You need to sign in to do that
Don't have an account?
Batch a not getting executed from Test Class
Hi Guys,
I Have a very different situation. I have a batch apex and test class.Now my requirement is executing batch from test class.When i am running test class the debug statements of Start,Execute and Finish Methods are getting displayed but in Apex Jobs there is no sign of the batch.Like the Batch name and all are not getting displayed in Apex Jobs.
I Have a very different situation. I have a batch apex and test class.Now my requirement is executing batch from test class.When i am running test class the debug statements of Start,Execute and Finish Methods are getting displayed but in Apex Jobs there is no sign of the batch.Like the Batch name and all are not getting displayed in Apex Jobs.
global class BatchClassexample implements Database.Batchable<sObject> { global String query = 'SELECT Id,Name FROM Account where name=:filter '; global Database.QueryLocator start(Database.BatchableContext BC) { system.debug('inside methiod----'); String filter='Client'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Account> scope) { //User u=[SELECT username from user where profileid='00e28000000sxOR']; system.debug('inside execute::'+scope); for(Account a : scope) { a.Name = a.Name + '(newyork)'; System.debug('::::::: execute'); update a; } system.debug('scope ::: '+scope); // update scope; system.debug('scope after ::: '+scope); //system.runAs(u){} } global void finish(Database.BatchableContext BC) { system.debug('inside finish'); } } //Test class @isTest() public class BatchClassexampleTestClass { public static testMethod void testRunAs(){ Test.startTest(); BatchClassexample BC=new BatchClassexample(); Account a=new Account(name='Client'); insert a; /*Profile p = [SELECT Id FROM Profile WHERE Name='Standard Platform User']; User u = new User(Alias = 'standt', Email='standardplatformuser@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='standardplatformuser@testorg.com'); insert u;*/ User u=[SELECT username,ProfileId from user where profileid='00e28000000sxOR']; system.runAs(u){ System.debug('u :::::: '+u); System.debug('u.ProfileId :::::: '+u.ProfileId); DataBase.executeBatch(BC,1); System.debug('name ::: '+a.Name); Test.stopTest(); System.debug('name after ::: '+a.Name); } } }
A batch which gets executed in test classes will not appear under Apex Jobs.
Thanks for your reply.But i have a requirement--When a user submits any batch class the submittedby name should be other user.So i thought of writting test class which uses System.RunAs() method. So is my approach correct??