As of now test class code coverage 85%, but when we are validating the chageset getting 0% code coverage error saying `
STANDARD_PRICE_NOT_DEFINED No standard price defined for this product.
Please check my below test class and help us to avoid this error.
@isTest(SeeallData=false)
private class BatchOpportunityInstallbaseTest {
static testMethod void ValidateOpportunityInstallbase() {
Installed_Base_Details__c obj = new Installed_Base_Details__c();
obj.Name='test';
obj.Product_Family__c ='Automation';
obj.Product_Line__c ='COML IPC';
obj.IB_Product_Family__c ='test';
obj.IB_Product_Line__c ='test';
obj.IB_Product_Module__c='test';
insert obj;
Oppty_Business_Area_Of_IB_Creation__c obj1 = new Oppty_Business_Area_Of_IB_Creation__c(Name='DCS');
insert obj1;
GEOSPOpptyDefaults__c obj2 = new GEOSPOpptyDefaults__c(name='test',APMFamily__c='Test',AUTOFamily__c='test',BMSFamily__c='test',APMProduct__c='test',AUTOProduct__c='test',BMSProduct__c='test');
insert obj2;
Test.startTest();
Account acc = new Account();
acc.Name='TestAcc';
acc.salesAreaList__c = '';
acc.BillingCountry = 'SLOVAKIA';
acc.BillingCity = 'test city';
acc.BillingStreet = 'test street';
acc.ShippingCountry = 'SLOVAKIA';
acc.CSN__c='CSN1234';
acc.GEMDM_Customer_Connect_Request_Status__c ='Approved';
insert acc;
Id devRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('GEAC Flow Oppty').getRecordTypeId();
Opportunity opp =new Opportunity();
opp.AccountId = acc.id;
// Changed the Opportunity stage value from AC5-Closed Won to Closed - Booked by Sagar on 24 Feb 2017 for US-03283
opp.StageName='Closed - Booked';
opp.name='test Opp';
opp.CloseDate = system.today().adddays(-2);
opp.recordTypeid=devRecordTypeId ;
opp.ForecastCategoryName ='Pipeline';
opp.ForecastCategoryName ='Pipeline';
opp.Amount =200;
opp.Topics__c ='Power Gen';
opp.CurrencyIsoCode ='USD';
opp.GEAC_Product_Area_of_Interest__c='DCS';
insert opp;
Test.stopTest();
Pricebook2 pb = new Pricebook2(Name='testDIE');
insert pb;
Product2 prod = new Product2(Name = 'Laptop X200',Family = 'Automation',Product_Line__c='COML IPC');
insert prod;
// PricebookEntry pbe1 =new PricebookEntry(unitprice=2,Product2Id=prod.Id,Pricebook2Id=Test.getStandardPricebookId(),isActive=true,UseStandardPrice = false);
PricebookEntry pbe2 =new PricebookEntry(unitprice=2,Product2Id=prod.Id,Pricebook2Id=pb.id,isActive=true,UseStandardPrice = false);
insert pbe2;
OpportunityLineItem olii = new OpportunityLineItem (Quantity=2, OpportunityId=opp.Id, TotalPrice=10.1, PriceBookEntryId=pbe2.id);
insert olii;
BatchOpportunityInstallbase objBatch = new BatchOpportunityInstallbase ();
Database.executeBatch(objBatch);
}
}
Thanks
PricebookEntry pbe1 = new PricebookEntry(...
line commented out? The error you're getting is complaining about theprod
you're creating in the test not having aPricebookEntry
for the standard pricebook. That one commented out line should (mostly) solve your issues (you'll need to insert that pbe as well).