You need to sign in to do that
Don't have an account?
goutham.tatineni1.3893010493585044E12
Help With Test class for Batch Apex on Opportunity Line Item
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.
@isTest(seeAllData=true) private class TestConversionRate { @isTest static void MyUnitTest() { // Set up some local variables String opportunityName = 'My Opportunity'; String standardPriceBookId = ''; PriceBook2 pb2Standard = [select Id from Pricebook2 where isStandard=true]; standardPriceBookId = pb2Standard.Id; Account a = new Account(Name = 'Berlington'); Insert a; // set up opp and Verify that the results are as expected. Opportunity o = new Opportunity(AccountId = a.id, Name=opportunityName, StageName='Discovery', CloseDate=Date.today()); insert o; Opportunity opp = [SELECT Name FROM Opportunity WHERE Id = :o.Id]; //System.assertEquals(opportunityName, 'Berlington - 0 -'); // set up product2 and Verify that the results are as expected. Product2 p2 = new Product2(Name='Test Product',isActive=true); insert p2; Product2 p2ex = [SELECT Name FROM Product2 WHERE Id = :p2.Id]; //System.assertEquals('Test Product', p2ex.Name); // set up PricebookEntry and Verify that the results are as expected. PricebookEntry pbe = new PricebookEntry(Pricebook2Id=standardPriceBookId, Product2Id=p2.Id, UnitPrice=99, isActive=true); insert pbe; PricebookEntry pbeex = [SELECT Pricebook2Id FROM PricebookEntry WHERE Id = :pbe.Id]; //System.assertEquals(standardPriceBookId, pbeex.Pricebook2Id); Win_Rate__c w = new Win_Rate__c(Name = 'Manpower - Brazil - 121-180',Win_rate__c = 90 ); Insert W; // set up OpportunityLineItem and Verify that the results are as expected. OpportunityLineItem oli = new OpportunityLineItem(PriceBookEntryId=pbe.Id, OpportunityId=o.Id,WinRate__c = w.id,Hidden_Name__c = w.name, Quantity=1, TotalPrice=99); insert oli; OpportunityLineItem oliex = [SELECT PriceBookEntryId FROM OpportunityLineItem WHERE Id = :oli.Id]; System.assertEquals(pbe.Id, oliex.PriceBookEntryId); opportunityLineItem Oppl = [Select Id,Name ,WinRate__c ,Hidden_Name__c from OpportunityLineItem where id =:oli.id]; system.assertnotEquals(oppl.WinRate__c ,''); } static testMethod void BatchProcessAccount_TestMethod (){ Test.StartTest(); UpdateWinRateBatch objBatch = new UpdateWinRateBatch(); ID batchprocessid = Database.executeBatch(objBatch); Test.StopTest(); } }
Also, depending on your structure, if you are kicking off another batch job or in other words chaining batch jobs, then that would likely also result in an exception. However, it doesn't look like this is the case.
Try removing the dependency on SeeAllData, and you should have better luck with your unit test.