+ Start a Discussion
pacstratspacstrats 

Unit Test for Visualforce Wizard

Help!

 

I created the following VF pages along with the custom controller based on the example from the SFDC cookbook (almost word for word) but I have no idea how to promote to production since I have no idea how to write the unit test to validate the coverage (only at 51%).  Any help would be appreciated.

 

Page 1 of 3

<apex:page controller="newDonationController"tabStyle="Opportunity">

<apex:sectionHeader title="NewCustomerOpportunity"subtitle="Step1of3"/>

<apex:form >

<apex:pageBlock title="CustomerInformation">

<apex:facet name="footer">

<apex:commandButton action="{!step2}"value="Next"styleClass="btn"/>

</apex:facet>

 

<apex:pageBlockSection title="AccountInformation">

<apex:panelGrid columns="2">

<apex:outputLabel value="Account Name"for="accountName"/>

<apex:inputField id="accountName"value="{!account.name}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

<apex:pageBlockSection title="ContactInformation">

<apex:panelGrid columns="2">

<apex:outputLabel value="First Name"for="contactFirstName"/>

<apex:inputField id="contactFirstName"value="{!contact.firstName}"/>

<apex:outputLabel value="Last Name"for="contactLastName"/>

<apex:inputField id="contactLastName"value="{!contact.lastName}"/>

<apex:outputLabel value="Phone"for="contactPhone"/>

<apex:inputField id="contactPhone"value="{!contact.phone}"/>

<apex:outputLabel value="Email"for="contactEmail"/>

<apex:inputField id="contactEmail"value="{!contact.email}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

</apex:pageBlock>

</apex:form>

</apex:page>

Page 2 of 3

<apex:page controller="newDonationController"

tabStyle="Opportunity">

<apex:sectionHeader title="NewCustomerOpportunity"

subtitle="Step2of3"/>

<apex:form>

<apex:pageBlock title="Donation Information">

<apex:facet name="footer">

<apex:outputPanel>

<apex:commandButton action="{!step1}" value="Previous"

styleClass="btn"/>

<apex:commandButton action="{!step3}" value="Next"

styleClass="btn"/>

</apex:outputPanel>

</apex:facet>

 

<apex:pageBlockSection title="Donation Information">

<apex:panelGrid columns="2">

<apex:outputLabel value="Donation Name"

for="opportunityName"/>

<apex:inputField id="opportunityName"

value="{!opportunity.name}"/>

<apex:outputLabel value="Amount"

for="opportunityAmount"/>

<apex:inputField id="opportunityAmount"

value="{!opportunity.amount}"/>

<apex:outputLabel value="Close Date"

for="opportunityCloseDate"/>

<apex:inputField id="opportunityCloseDate"

value="{!opportunity.closeDate}"/>

<apex:outputLabel value="Type"

for="opportunityType"/>

<apex:inputField id="opportunityType"

value="{!opportunity.type}"/>

<apex:outputLabel value="Stage"

for="opportunityStageName"/>

<apex:inputField id="opportunityStageName"

value="{!opportunity.stageName}"/>

<apex:outputLabel value="Payment Type"

for="opportunityPaymentType"/>

<apex:inputField id="opportunityPaymentType"

value="{!opportunity.NFG__Payment_Type__c}"/>

<apex:outputLabel value="Check Date"

for="opportunityCheckDate"/>

<apex:inputField id="opportunityCheckDate"

value="{!opportunity.Check_Date__c}"/>

<apex:outputLabel value="Check #"

for="opportunityCheckNo"/>

<apex:inputField id="opportunityCheckNo"

value="{!opportunity.Check_Number__c}"/>

<apex:outputLabel value="Deposit Date"

for="opportunityDepositDate"/>

<apex:inputField id="opportunityDepositDate"

value="{!opportunity.Bank_Deposit_Date__c}"/>

<apex:outputLabel value="Primary Campaign"

for="opportunityCampaign"/>

<apex:inputField id="opportunityCampaign"

value="{!opportunity.CampaignId}"/>

<apex:outputLabel value="Internet Source"

for="opportunityInternetSource"/>

<apex:inputField id="opportunityInternetSource"

value="{!opportunity.NFG__Internet_Donation_Source__c}"/>

<apex:outputLabel value="Program Desingation"

for="opportunityProgram"/>

<apex:inputField id="opportunityProgram"

value="{!opportunity.Program_Designation__c}"/>

<apex:outputLabel value="Contact Role: {!contact.firstName} {!contact.lastName}"

for="contactRole"/><apex:inputField id="contactRole"

value="{!role.role}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

</apex:pageBlock>

</apex:form>

</apex:page>

Page 3 of 3

<apex:page controller="newDonationController"

tabStyle="Opportunity">

<apex:sectionHeader title="NewCustomerOpportunity"

subtitle="Step3of3"/>

<apex:form>

<apex:pageBlock title="Confirmation">

<apex:facet name="footer">

<apex:outputPanel >

<apex:commandButton action="{!step2}"

value="Previous"styleClass="btn"/>

<apex:commandButton action="{!save}"

value="Save"styleClass="btn"/>

</apex:outputPanel>

</apex:facet>

 

<apex:pageBlockSection title="Account Information">

<apex:panelGrid columns="2">

<apex:outputText value="Account Name:"/>

<apex:outputText value="{!account.name}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

<apex:pageBlockSection title="Contact Information">

<apex:panelGrid columns="2">

<apex:outputText value="First Name:"/>

<apex:outputText value="{!contact.firstName}"/>

<apex:outputText value="Last Name:"/>

<apex:outputText value="{!contact.lastName}"/>

<apex:outputText value="Phone:"/>

<apex:outputText value="{!contact.phone}"/>

<apex:outputText value="Email:"/>

<apex:outputText value="{!contact.email}"/>

<apex:outputText value="Role"/>

<apex:outputText value="{!role.role}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

<apex:pageBlockSection title="Donation Information">

<apex:panelGrid columns="2">

<apex:outputText value="Donation Name:"/>

<apex:outputText value="{!opportunity.name}"/>

<apex:outputText value="Amount:"/>

<apex:outputText value="{!opportunity.amount}"/>

<apex:outputText value="Type:"/>

<apex:outputText value="{!opportunity.type}"/>

<apex:outputText value="Close Date:"/>

<apex:outputText value="{!opportunity.closeDate}"/>

<apex:outputText value="Stage:"/>

<apex:outputText value="{!opportunity.stagename}"/>

<apex:outputText value="Payment Type:"/>

<apex:outputText value="{!opportunity.NFG__Payment_Type__c}"/>

<apex:outputText value="Check Date:"/>

<apex:outputText value="{!opportunity.Check_Date__c}"/>

<apex:outputText value="Check #:"/>

<apex:outputText value="{!opportunity.Check_Number__c}"/>

<apex:outputText value="Check Deposit Date:"/>

<apex:outputText value="{!opportunity.Bank_Deposit_Date__c}"/>

<apex:outputText value="Primary Campaign:"/>

<apex:outputText value="{!opportunity.campaignid}"/>

<apex:outputText value="Internet Source:"/>

<apex:outputText value="{!opportunity.NFG__Internet_Donation_Source__c}"/>

<apex:outputText value="Program Designation:"/>

<apex:outputText value="{!opportunity.Program_Designation__c}"/>

</apex:panelGrid>

</apex:pageBlockSection>

 

</apex:pageBlock>

</apex:form>

</apex:page>

public class newDonationController {

Account account;

Contact contact;

Opportunity opportunity;

OpportunityContactRole role;

Campaign campaign;

 

public Account getAccount() {

if(account == null)

return account;

}

public Contact getContact() {

if(contact == null) contact = new Contact();

return contact;

}

public Opportunity getOpportunity() {

if(opportunity == null) opportunity = new Opportunity();

return opportunity;

}

public OpportunityContactRole getRole() {

if(role == null) role = new OpportunityContactRole();

return role;

}

public PageReference step1() {

return Page.DonationStep1;

}

public PageReference step2() {

return Page.DonationStep2;

}

public PageReference step3() {

return Page.DonationStep3;

}

public PageReference save() {

account.phone = contact.phone;

account.NFG__Email__c = contact.email;

insert account;

 

contact.accountId = account.id;

insert contact;

 

opportunity.accountId = account.id;

insert opportunity;

 

role.opportunityId = opportunity.id;

role.contactId = contact.id;

insert role;

 

PageReference donationPage = new PageReference('/' + opportunity.id);

donationPage.setRedirect(true);return donationPage;

}

}

 

Message Edited by pacstrats on 03-30-2010 05:31 PM
dmotedmote

I am looking for a test also for a VF page I created that is very similar to this.  Did you figure out how to do this?

 

David

Big Chewy PretzelsBig Chewy Pretzels

I'm looking for something very similar as well.  Has anyone had any luck yet?