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
a!a! 

Test code coverage

public with sharing class account_name {
public list<account> accounts=new List<Account>();
Account acc_con=new Account();
public Account getaccdet()
{
return acc_con;
}
public account_name()
{
}
public class innerClass
{
public Account accc{get; set;}
public Integer UniqId{get;set;}
}
public List<innerClass> IList = new List<innerClass>();
public Integer i=0;


public void add()
{
innerclass inn=new innerclass();
Account acc_det=new Account();
acc_det.Name=acc_con.Name;
acc_det.Industry=acc_con.Industry;
acc_det.Phone=acc_con.Phone;
i++;
inn.accc=acc_det;
inn.uniqid=i;
System.debug('******'+inn);
IList.add(inn);
System.debug('iiii'+IList);
acc_con=new account();
}
public List<innerClass> getAlist()
{
return IList;
}
public void save1()
{ 

List<Account> insertaccount = new List<Account>();
for(InnerClass IPs : iLIst)
{
//IPs.accc.AccouontId=acc_con.id;
insertaccount.add(IPs.accc);
System.debug('//////'+insertaccount);
}
insert insertaccount;
}

public void deleteITem()
{
String i=System.CurrentPageReference().getParameters().get('aid');
System.debug('/////'+i);
Integer k = 0;
boolean b = true;
for(InnerClass IP : IList)
{
System.debug('*************'+IP.uniqid);

if(IP.uniqid==Integer.valueOf(System.CurrentPageReference().getParameters().get('aid')))
{ 
b=false;
break;
}
k++;
}
if(!b)
{
IList.remove(k);
}
}
//--------------Test Method--------------//
public static testmethod void test()
{
account_name obj=new account_name();
obj.getaccdet();
obj.add(); 
obj.getAlist(); 
obj.save1();
obj.deleteITem();
}
}

 

Hi 

 

 

public void deleteITem()
{
String i=System.CurrentPageReference().getParameters().get('aid');
System.debug('/////'+i);
Integer k = 0;
boolean b = true;
for(InnerClass IP : IList)
{
System.debug('*************'+IP.uniqid);

if(IP.uniqid==Integer.valueOf(System.CurrentPageReference().getParameters().get('aid')))
{ 
b=false;
break;
}
k++;
}
if(!b)
{
IList.remove(k);
}
}

 am not covering the above code in the test class, plese look at this

 

Thanks in Advance

 

HariDineshHariDinesh

Hi,

 

try this.....

In Test method.

 

//give all required fields
account_name obj=new account_name(name='hhhh',.........); insert obj; ApexPages.currentPage().getParameters().put('aid','obj.ID');

Id this does not solves your problem please post you code by Highlighting (which is not covered).

a!a!
public void deleteITem()
{
String i=System.CurrentPageReference().getParameters().get('aid');
System.debug('/////'+i);
Integer k = 0;
boolean b = true;
for(InnerClass IP : IList)
{
System.debug('*************'+IP.uniqid);

if(IP.uniqid==Integer.valueOf(System.CurrentPageReference().getParameters().get('aid')))
{ 
b=false;
break;
}
k++;
}
if(!b)
{
IList.remove(k);
}
}

 above code is not covered in the test class.