You need to sign in to do that
Don't have an account?
Rung41
Help with Test method please.
I have written (with much help from Darshan Farswan ) a test class with an extenison. I need some help writting the test method. I have started writting it but I'm not sure if I am heading in the right direction.
Here is my test method so far:
public class testNewRentalOpportunity {
static testMethod void myUnitTest(){
ApexPages.standardController controller = new ApexPages.standardController(new Renter__c());
NewRenterOpportunity nro = new NewRenterOpportunity(controller);
test.startTest();
nro.rentr.Name = 'Alice Cooper';
nro.rentr.Renters_Phone__c = '(456) 125-7895';
nro.rentr.Renters_Email__c = 'acooper@bfr.com';
test.stopTest();
}
}
Here is my Visualforce page:
<apex:page standardController="Renter__c" extensions="NewRenterOpportunity"> <apex:pagemessages /> <apex:pageBlock title="Introduction"> <apex:pageBlockSection title="Introduce Brook and yourself"> <b><font color="green">Thank you for calling Brook Furniture Rental, This is {!$User.FirstName}!"</font></b><p/> </apex:pageBlockSection> </apex:pageBlock> <apex:form > <apex:pageBlock title="Renter's Information"> <apex:pageBlockSection columns="2" title="Ask for the Customer's Information"> <apex:inputField value="{!Renter__c.Renter_s_First_Name__c}" /> <apex:inputField value="{!Renter__c.Name}" /> <apex:inputField value="{!Renter__c.Renters_Phone__c}" /> <apex:inputField value="{!Renter__c.Renters_Email__c}" /> <apex:pageBlockSectionItem ><b>Tell me about your situation and your need for renting furniture?</b> </apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Why_the_need_to_rent_furniture__c}" style="Width:80%;Height:80px" /> <p/> <apex:inputField value="{!Renter__c.Classification__c}" /> <p/> <apex:pageBlockSectionItem ><b>How long will you to rent furniture? </b> </apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Lease_Terms__c}" /> <p/> <apex:pageBlockSectionItem ><b> How did you hear about Brook? </b></apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Source__c}" /> <p/> <br></br><br></br> <br> <apex:pageBlockSectionItem ><b><font color="green"> Provide 20-30 second overview of our product and service. -- Offer to walk them through the website.</font></b></apex:pageBlockSectionItem><p/> </br> <br></br> <apex:pageBlockSectionItem ><b>What is the name of your Company?</b></apex:pageBlockSectionItem><p/> <apex:inputField id="Company" value="{!Renter__c.Company__c}" /><p/> <apex:pageBlockSectionItem > <b>Do you have a price range that you’re working with for renting furniture?</b></apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Budget__c}" /><p/> <br></br><br></br> <apex:pageBlockSectionItem ><b><font color="green"> Our collections are STARTING POINTS - be sure to add: additional end table, nightstand, upgraded bed, lamps.</font></b></apex:pageBlockSectionItem><p/> <br></br> <apex:pageBlockSectionItem > <b>Will you need? </b> </apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Need_Housewares__c}" /> <p/> <apex:inputField value="{!Renter__c.Need_Electronics_Appliances__c}" /><p/> <apex:inputField value="{!Renter__c.Need_Office_Furniture__c}" /><p/> <apex:inputField value="{!Renter__c.Need_Finishing_Touches__c}" /><p/> <apex:inputField value="{!Renter__c.Details_of_what_they_need__c}" style="Width:80%;Height:80px" /><p/> <br></br><br></br> <apex:pageBlockSectionItem > <b><font color="green"> Present distribution fee and waiver. Offer to create a lease or quote </font></b> </apex:pageBlockSectionItem><p/> <br></br> <apex:pageBlockSectionItem > <b><font color="green"> Find out when they will be making a decision. </font></b></apex:pageBlockSectionItem><p/> <br></br> <apex:pageBlockSectionItem ><b><font color="green"> Instill urgency about fast moving furniture or closing delivery dates. </font></b></apex:pageBlockSectionItem><p/> <br></br> <apex:pageBlockSectionItem > <b><font color="green"> Arrange specific day and time for follow up. </font></b></apex:pageBlockSectionItem><p/> <br></br><br></br> <apex:pageBlockSectionItem ><b> Are there other’s in your company who may need to rent furniture as well? </b> </apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Other_that_need_to_rent__c}" /> <p/> <apex:inputField value="{!Renter__c.Other_Potential_Renters__c}" style="Width:80%;Height:80px" /> <p/> <br></br><br></br> <apex:pageBlockSectionItem ><b> Delivery Dates </b> </apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Delivery_Date__c}" /> <apex:inputField value="{!Renter__c.Alternate_Delivery_Date__c}" /> <apex:pageBlockSectionItem ><b> Delivery Address </b> </apex:pageBlockSectionItem><p/> <apex:inputField value="{!Renter__c.Delivery_Street__c}" style="Width:50%;Height:40px" /> <p/> <apex:inputField value="{!Renter__c.Delivery_City__c}"/><p/> <apex:inputField value="{!Renter__c.Delivery_State__c}"/> <p/> <apex:inputField value="{!Renter__c.Delivery_Zip__c}"/><p/> <apex:inputField value="{!Renter__c.Showroom__c}" /> <p/> </apex:pageBlockSection> </apex:pageBlock> <apex:commandButton value="Cancel" action="{!cancel}"/> <apex:commandButton action="{!save}" value="Continue" /> </apex:form> </apex:page>
And here is my extension:
public class NewRenterOpportunity { public Opportunity opp{get;set;} public Renter__c rentr{get;set;} public NewRenterOpportunity(ApexPages.StandardController controller) { rentr = (Renter__c)controller.getRecord(); Id id = ApexPages.currentPage().getParameters().get('id'); } public PageReference Save(){ insert rentr; opp = new Opportunity(); opp.Name = rentr.Renter_s_First_Name__c + ' ' + rentr.Name; opp.Renters_Email__c = rentr.Renters_Email__c; opp.Renters_Phone__c = rentr.Renters_Phone__c; opp.StageName = 'Proposal/Price Quote'; opp.CloseDate = System.today()+2; opp.Classification__c = rentr.Classification__c; opp.Lease_Term__c = rentr.Lease_Terms__c; opp.Residential_Opportunity_Source__c = rentr.Source__c; opp.Renter_s_Price_Range__c = rentr.Budget__c; opp.Need_Office_Furniture__c = rentr.Need_Office_Furniture__c; opp.Need_Housewares__c = rentr.Need_Housewares__c; opp.Need_Finishing_Touches__c = rentr.Need_Finishing_Touches__c; opp.Need_Electronics_Appliances__c = rentr.Need_Electronics_Appliances__c; opp.Other_Potential_Renters__c = rentr.Other_that_need_to_rent__c; opp.Pertainent_Notes__c = rentr.Why_the_need_to_rent_furniture__c; opp.Potential_Renters__c = rentr.Other_Potential_Renters__c; opp.Delivery_Date__c = rentr.Delivery_Date__c; opp.Alternate_Delivery_Date__c = rentr.Alternate_Delivery_Date__c; opp.Delivery_Street__c = rentr.Delivery_Street__c; opp.Delivery_City__c = rentr.Delivery_City__c; opp.Delivery_State__c = rentr.Delivery_State__c; opp.Delivery_Zip__c = rentr.Delivery_Zip__c; opp.Showroom__c = rentr.Showroom__c; String AccountId; opp.Corporation__c = rentr.Company__c; insert opp; PageReference ref = new PageReference('/'+opp.id); return ref; } public PageReference NewRenters(){ return null; } public PageReference Cancel(){ return null; } }
Call the methods defined in your exntension from your test class in this way-
nro.save();
nro.newrenters();
nro.cancel();
Please note that you will require to call each method getting called from your VF page from the test class to cover your logic.