You need to sign in to do that
Don't have an account?

Coverage 100% for my class
So i have my test class which i wrote:
@isTest
public class Controller2TestClass
{
static testMethod void testMethod1()
{
Account acc = new Account();
showAccount showAcc = new showAccount();
acc.Name='Test';
acc.Phone='0644204232';
showAcc.save();
PageReference pageRef = Page.screen2 ;
Test.setCurrentPage(pageRef);
String checkIdAccount = ApexPages.currentPage().getParameters().get('id');
System.assertEquals(checkIdAccount, acc.id);
}
}
VF Page:
<apex:page controller="showAccount" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputField value="{!account.name}"/>
<apex:inputField value="{!account.phone}"/>
<apex:commandButton value="update" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
And this is the class that I'm testing. I'm only covering 33% and I wonder how can I cover 100%? What I've missed?
public class showAccount
{
public Account account{get;set;}
public showAccount()
{
Id idAccount = apexpages.currentPage().getParameters().get('id');
account=[Select ID, Name, Phone from Account where id = : idAccount];
}
public pageReference save(){
update account;
PageReference pageRef = new PageReference('/apex/screen3');
pageRef.getParameters().put('id', account.Id);
return pageRef;
}
}
Let us know if this will help you
All Answers
I made some changes in your test class. This will be helpful for you. Mark as a solution if it helps you.
Thanks
Let us know if this will help you
It works!
Thank you Armit, damn you are good!