You need to sign in to do that
Don't have an account?
domdick
Urgent Help on Unit Test
Hi,
Thanks for all expert here to help everytime with any query.
I have controller class and test class. The test works fine except this line.... from controller class. Any solution to make it work?
Thanks,
public list <OpportunityLineItem> getLicenceServicelist () {
return [SELECT id, ServiceDate, License_service__c, PricebookEntry.Product2.Quote_service_group__c, Opportunity.name FROM OpportunityLineItem WHERE License_service__c = 1 AND Opportunity.id =
:System.currentPageReference().getParameters().get('id')];
} /* how can i run the test class for this line*/
controller class:
public class OppsControllerExtension { private final Opportunity opps; public OppsControllerExtension(ApexPages.StandardController stdController) { this.opps = (Opportunity)stdController.getRecord(); } List<OpportunityLineItem> OppsLicence = [SELECT id, ServiceDate, Opportunity.name FROM OpportunityLineItem WHERE License_service__c = 1 AND Opportunity.id = :System.currentPageReference().getParameters().get('id')]; public integer getLicenceRowNumber() { if (OppsLicence.size() >= 1) return OppsLicence.size() - 1; else return 0; } public list <OpportunityLineItem> getLicenceServicelist () {
return [SELECT id, ServiceDate, License_service__c, PricebookEntry.Product2.Quote_service_group__c, Opportunity.name FROM OpportunityLineItem WHERE License_service__c = 1 AND Opportunity.id =
:System.currentPageReference().getParameters().get('id')];
} }
Test class:
@IsTest(SeeAllData=true) private class OppsContollerExtensionTestV2 { static testMethod void myUnitTestforNull() { Pricebook2 pb = [Select Id, Name From Pricebook2 Where IsStandard = true Limit 1];//Id = '01sM00000000ApLIAU' Limit 1];//IsStandard = true Limit 1]; /* Setup a basic opportunity */ Opportunity o = new Opportunity(); o.Name = 'TEST'; o.AccountId = '001M0000002PGFO'; o.CloseDate = Date.today(); o.StageName = 'Interest';o.Pricebook2Id = pb.id; Database.insert(o); /* Create a product2 */ Product2 p = new Product2(); p.Name = 'TEST'; Database.insert(p); /* Create a pricebook entry. */ PricebookEntry pbe = new PricebookEntry(); pbe.Pricebook2Id = pb.id; pbe.Product2Id = p.id; pbe.IsActive = true; pbe.UnitPrice = 50; Database.insert(pbe); /* Create a line item */ OpportunityLineItem i = new OpportunityLineItem(); i.opportunityId = o.id; i.pricebookentryid = pbe.id; i.quantity = 4; i.TotalPrice = 2000; Database.insert(i); /* Set the request parameter that the constructor for quoteExt is expecting */ Pagereference pref = Page.quote1PDF; pref.getParameters().put('id',o.Id); Test.setCurrentPage(pref); ApexPages.StandardController stdcontroller = new ApexPages.Standardcontroller(o); OppsControllerExtension opptyCtrlObj = new OppsControllerExtension (stdcontroller); Test.startTest(); integer licenceRowNumebr = opptyCtrlObj.getLicenceRowNumber(); Test.stopTest(); } static testMethod void myUnitTestforLicense() { Pricebook2 pb = [Select Id, Name From Pricebook2 Where IsStandard = true Limit 1];//Id = '01sM00000000ApLIAU' Limit 1];//IsStandard = true Limit 1];
/* Setup a basic opportunity */
Opportunity o = new Opportunity(); o.Name = 'TEST'; o.AccountId = '001M0000002PGFO'; o.CloseDate = Date.today(); o.StageName = 'Interest';o.Pricebook2Id = pb.id; Database.insert(o); /* Create a product2 */ Product2 p = new Product2(); p.Name = 'TEST'; p.Quote_service_group__c='Licence'; Database.insert(p); /* Create a pricebook entry. */ PricebookEntry pbe = new PricebookEntry(); pbe.Pricebook2Id = pb.id; pbe.Product2Id = p.id; pbe.IsActive = true; pbe.UnitPrice = 50; Database.insert(pbe);
/* Create a line item */
OpportunityLineItem i = new OpportunityLineItem(); i.opportunityId = o.id; i.pricebookentryid = pbe.id; i.quantity = 4; i.TotalPrice = 2000; Database.insert(i);
/* Set the request parameter that the constructor for quoteExt is expecting */
Pagereference pref = Page.quote1PDF;
pref.getParameters().put('id',o.Id);
Test.setCurrentPage(pref);
ApexPages.StandardController stdcontroller = new ApexPages.Standardcontroller(o); OppsControllerExtension opptyCtrlObj = new OppsControllerExtension (stdcontroller);
Test.startTest();
integer licenceRowNumebr = opptyCtrlObj.getLicenceRowNumber();
Test.stopTest(); } }
just add opptyCtrlObj.getLisenceServiceList(); in your test class .
I have tried this earlier but didn't work and through an error of
"Method does not exist or incorrect signature: [OppsControllerExtension].getLisenceServiceList()"
Any other workaround?
Hopefully this isn't the issue, but your method was misspelled from what you are stating here on the forums vs your class.