You need to sign in to do that
Don't have an account?
toro
Test problem
Hello,
I'm trying to create test method for my control class.
Here is my control class;
public class VFController { private final OpportunityLineItem o; public VFController(ApexPages.StandardController stdController) { this.o = (OpportunityLineItem)stdController.getRecord(); } public string theId; // Code we will invoke on page load. public PageReference autoRun() { theId = ApexPages.currentPage().getParameters().get('id'); OpportunityLineItem newprod; string oppID; string prodID; if (theId == null) { // Display the Visualforce page's content if no Id is passed over return null; } upsert(o); for (OpportunityLineItem o:[select Buffers__c, ATC__c, CNC__c, CTS_PSI__c, Chip_Conveyor__c, CreatedById, CreatedDate, ServiceDate, IsDeleted, Head_Change__c, Head_Type__c, OpportunityId, L_U__c, LastModifiedById, LastModifiedDate, Description, Id, ListPrice, Number_of_Pallets__c, Other_Options__c, PricebookEntryId, Product_Family__c, Quantity, RGV__c, Ship_Date__c, SortOrder, Spindle__c, Spindle_Taper__c, SystemModstamp, Table__c, TotalPrice, Delivery_Date__c from OpportunityLineItem where id =:theId]) { // Do all the dirty work we need the code to do upsert(o); newprod = o.clone(false); newprod.Machine_SN__c = 'TBD'; oppID = newprod.OpportunityId; insert newprod; } // Redirect the user back to the original page PageReference pageRef = new PageReference('/' + newprod.id + '/e?retURL='+ oppID); pageRef.setRedirect(true); return pageRef; }
and here is my test method:
static testMethod void testAutoRun(){ OpportunityLineItem opl = new OpportunityLineItem(); opl = [select Id, OpportunityId, Spindle__c, Quantity, Table__c, Ship_Date__c, Delivery_Date__c, Machine_SN__c,TotalPrice from OpportunityLineItem limit 1]; pagereference pageref = new pagereference('/'+opl.Id); Test.setcurrentpage(pageref); VFController vfc = new VFController(new ApexPages.StandardController(opl)); vfc.theId = opl.Id; vfc.autorun(); }
How can I put value on theId? The test always go with theId ==null and never gets lower half of the code because I can't put value in theId....
This is my first testmethod.
Does anyone can help me?
Thanks.
You might look into some code like this:
Note
More info at this link.
All Answers
I would suggest that if you want help, you make your code a bit more readable by adding line breaks and tabs instead of just posting one big block of text. Just saying.
I should have review before post ....here is the nice looking code. hopefully somebody can help.
Here is my test code
Thank you
You might look into some code like this:
Note
More info at this link.
Thank you.
This is the code I ended up and it covers 100%.