function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MonikaalladaMonikaallada 

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.

Best Answer chosen by Admin (Salesforce Developers) 
Laxman RaoLaxman Rao

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

Laxman RaoLaxman Rao

Can you paste your complete contoller

MonikaalladaMonikaallada

getdetails is the method in controller.

which is in the code..3rd line.

Laxman RaoLaxman Rao

try this :

 

static testMethod void accountdetails() {
Accountdetails obj = new Accountdetails();
// intitalize all the required fields
Account acc = obj.getdetails();
acc.Name = 'test';
obj.ad();
}

This was selected as the best answer
MonikaalladaMonikaallada

Thank you laxman,

 

Now i got how to do..