You need to sign in to do that
Don't have an account?
VSK98
Test code coverage for VF Page
Hi All,
I have written test class for one of my VF Page & covered upto 73% but i failed to cover morethan 75%. Here is my VF Page & Apex Classes
Here is Controller
Here is 29 th line is not covered ...............
Here is My Test Class
I have checked the debugs, SelectedAccountId its coming in test class but not in main controller..........I am struck here .......Please give me your valuable suggestions.......
Adv Thnx
VSK98
I have written test class for one of my VF Page & covered upto 73% but i failed to cover morethan 75%. Here is my VF Page & Apex Classes
<apex:page controller="DataTableEditRemoveController"> <apex:form id="form" > <apex:pageBlock title="Accounts"> <apex:pageMessages ></apex:pageMessages> <apex:pageBlockTable value="{!accs}" var="acc"> <apex:column > <apex:outputLink title="" value="/{!acc.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink> | <apex:commandLink action="{!DeleteAccount}" onclick="return confirm('Are you sure?')" value="Del"> <apex:param value="{!acc.Id}" name="accountid" assignTo="{!SelectedAccountId}"/> </apex:commandLink> </apex:column> <apex:column value="{!acc.Name}"/> <apex:column value="{!acc.BillingStreet}"/> <apex:column value="{!acc.BillingCity}"/> <apex:column value="{!acc.BillingPostalCode}"/> <apex:column value="{!acc.BillingCountry}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Here is Controller
public class DataTableEditRemoveController { public String getRow() { return null; } public List<Account> accs { get; set; } //used to get a hold of the account record selected for deletion public string SelectedAccountId { get; set; } public DataTableEditRemoveController() { //load account data into our DataTable LoadData(); } @Testvisible private void LoadData() { system.debug('Enter In the Constructor*****'); accs = [Select id, name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account limit 20]; } public PageReference DeleteAccount() { System.debug('SelectedAccountId: '+SelectedAccountId); accs = [select id,name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account where id=:SelectedAccountId]; System.debug('SIZEOFACC: '+accs.size()); if(accs.size()>0 && accs[0]!= null){ delete accs; System.debug('DELSIZEOFACC: '+accs.size()); SelectedAccountId = null; } //refresh the data LoadData(); return null; } }
Here is 29 th line is not covered ...............
Here is My Test Class
@istest public class DataTableEditRemoveController_Test{ static testmethod void Method_Test(){ Account acc = new Account(); acc.name = 'Test'; acc.Fax = '555555'; acc.BillingStreet = 'Korlagunta'; acc.BillingCity = 'Tirupati'; acc.BillingPostalCode = 'Tiruapti'; acc.BillingCountry = 'INDIA'; insert acc; // Delete acc; system.debug('ACCID******'+acc.id); Test.starttest(); pagereference pageref = page.Edit_Del_Hyperlink_Fun; Test.SetCurrentPageReference(pageref); pageref.getParameters().put('SelectedAccountId', String.valueOf(acc.Id)); string STRID = apexpages.currentpage().getparameters().put('SelectedAccountId',acc.id); System.assertEquals(STRID, acc.Id, 'ID\'s should match'); system.debug('PARAMID******'+apexpages.currentpage().getparameters().put('SelectedAccountId',acc.id)); DataTableEditRemoveController contrll = new DataTableEditRemoveController (); contrll.LoadData(); contrll.DeleteAccount(); list<Account> a =[select id,name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account where id=:STRID]; system.debug('LSTACCID******'+a.size()); Delete a; Test.stoptest();
I have checked the debugs, SelectedAccountId its coming in test class but not in main controller..........I am struck here .......Please give me your valuable suggestions.......
Adv Thnx
VSK98
DataTableEditRemoveController contrll = new DataTableEditRemoveController ();
contrll.SelectedAccountId = acc.id
contrll.LoadData();
contrll.DeleteAccount();
All Answers
DataTableEditRemoveController contrll = new DataTableEditRemoveController ();
contrll.SelectedAccountId = acc.id
contrll.LoadData();
contrll.DeleteAccount();
Test Class:
It's perfectly working now..........But i want to why
the above line not useful here.............Can you explain ?????????
Thnx
VSK 98
try this:-
Thanks
Ankur Saini
http://mirketa.com