You need to sign in to do that
Don't have an account?
how to write test method for this
this is my page
here in which i will enter the values in the required fields in VFpage and insert the account with the help of apex class.
<Apex:Form>
<apex:pageBlock Title="Add a new account" rendered="{!showresult}">
<apex:outputLabel for="a">AccountName: </apex:outputLabel>
<apex:inputField value="{!details.name}" id="a"/>
BillingCity: <apex:inputField value="{!details.billingcity}"/>
AccountNumber: <apex:inputField value="{!details.Accountnumber}"/>
<apex:commandButton value="save" action="{!ad}"/>
</apex:pageBlock>
</apex:form>
This is my class
Public class Accountdetails{
boolean showresult=true;
public Account getdetails() // after clicking the new button we get fields to create a new account those details set here
{
return b;
}
public pageReference ad()// after clicking the save button the insertion takes place.
{
insert b;
showresult = false;// the pageblock of the create account will be disable.
return null;
}
}
now please suggest me how to write test method for this.
I am not getting how to retrive the values from VF to test class.
Please any one can help me.
try this :
static testMethod void accountdetails() {
Accountdetails obj = new Accountdetails();
// intitalize all the required fields
Account acc = obj.getdetails();
acc.Name = 'test';
obj.ad();
}
All Answers
Can you paste your complete contoller
getdetails is the method in controller.
which is in the code..3rd line.
try this :
static testMethod void accountdetails() {
Accountdetails obj = new Accountdetails();
// intitalize all the required fields
Account acc = obj.getdetails();
acc.Name = 'test';
obj.ad();
}
Thank you laxman,
Now i got how to do..