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

How to write the test class for the following?
I have the below code.
public class mycontroller
{
public ApexPages.StandardSetController con{
get {
Id accId = system.currentPageReference().getParameters().get('Id');
str = String.valueOf(accId).left(3);
if(accId!=null && str == '001')
{
if(con!=null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([select id from relationship__c where acccount__c =: Accid]));
}
---
---
---
}
return con;
}
set;
}
}
I have tried with the below code but not entering into getter of the "public ApexPages.StandardSetController con"
@isTest(seeAllData=True)
private class ViewConnectioncontrollerTest1
{
static testMethod void ViewConnectioncontrollerTestMethod()
{
List<Account> acc = new List<Account>();
acc = [select Id,Name from Account limit 1];
ApexPages.currentPage().getParameters().put('accid', acc[0].id);
System.debug('********* acc id ********' +acc[0].id);
ApexPages.StandardSetController ssc = new ApexPages.Standardsetcontroller(acc);
ViewConnectioncontroller vcc = new ViewConnectioncontroller();
vcc.con = ssc;
// vcc.con.accid = acc[0].id;
}
}
pls help
public class mycontroller
{
public ApexPages.StandardSetController con{
get {
Id accId = system.currentPageReference().getParameters().get('Id');
str = String.valueOf(accId).left(3);
if(accId!=null && str == '001')
{
if(con!=null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([select id from relationship__c where acccount__c =: Accid]));
}
---
---
---
}
return con;
}
set;
}
}
I have tried with the below code but not entering into getter of the "public ApexPages.StandardSetController con"
@isTest(seeAllData=True)
private class ViewConnectioncontrollerTest1
{
static testMethod void ViewConnectioncontrollerTestMethod()
{
List<Account> acc = new List<Account>();
acc = [select Id,Name from Account limit 1];
ApexPages.currentPage().getParameters().put('accid', acc[0].id);
System.debug('********* acc id ********' +acc[0].id);
ApexPages.StandardSetController ssc = new ApexPages.Standardsetcontroller(acc);
ViewConnectioncontroller vcc = new ViewConnectioncontroller();
vcc.con = ssc;
// vcc.con.accid = acc[0].id;
}
}
pls help
If u talk about test class then u have to keep in mind that ur dealing with a dummy database which consists nothing that means there will be no record in the database then in ur code how can u retrieve a account fro database without having account records. So first insert the record and then retrieve the record. Process the record further..
Thanks,
pradeep.
Thanks for the reply.
Since i have used Annotation "seeAllData = True" at the top , I m retrieving the data from data base.
even i have tried with the following but no use...
@isTest
private class ViewConnectioncontrollerTest1
{
static testMethod void ViewConnectioncontrollerTestMethod()
{
Account acc = new Account();
acc.name = 'test Account';
insert acc;
List<Account> acc1 = new List<Account>();
acc1 = [select id, name from Account where id =: acc.id];
ApexPages.currentPage().getParameters().put('accid', acc1[0].id);
System.debug('********* acc id ********' +acc1[0].id);
ApexPages.StandardSetController ssc = new ApexPages.Standardsetcontroller(acc1);
mycontroller vcc = new mycontroller();
}
}
I missed it and the above code seems good and at last add the method name ie after
mycontroller vcc = new mycontroller();
acc.METHODNAME();
Add that and check
Thanks,
pradeep.
the methods are as follows,
public void next() {
con.next();
}
public void previous() {
con.previous();
}
etc..
so , if i call the methods like
vcc.next();
vcc.prev();
above statements are not excecuting the controller since con is null;
so , My question is how to set the con value which is inide the " public ApexPages.StandardSetController con{
get { .... Setting the value for con here...} }"
i.e the test method is not covering the code which is inside the getter;
have u tryed like this
mycontroller vcc = new mycontroller(ssc);
Thanks,
pradeep
When I tried that i got error; " Constructor not defined: [ViewConnectioncontroller].<Constructor>(ApexPages.StandardSetController) "
since there is not such contructor.