You need to sign in to do that
Don't have an account?
calling a list in testcoverage
hiii this is my test class....i just want to write a test coverage for this code.....but i got only 50% of code coverage...can anyone plsss...help me out....
public class MultipleStdntView1_AC
{
public pagereference save()
{
return null;
}
String recordId;
public MultipleStdntView1_AC()
{
recordId = system.currentpagereference().getparameters().get('id');
c = [select Name,dept_email__c,dept_ID__c from department__c where id =: recordId];
stdntlist = [Select Name,Email__c,phone__c,percentage__c from Student__c where department__c =: c.id];
}
Department__c c = new Department__c();
public department__c getdepartmentDetails()
{
return c;
}
List<Student__c> stdntlist = new List<Student__c>();
public List<Student__c> getstudentDetails()
{
return stdntlist;
}
public PageReference edit()
{
return null;
}
public PageReference deleteRecords()
{
return null;
}
}
the red colored lines are the uncovered....
and also can you pls..tel me about "how to call a list & a loop?
All Answers
Can you please post your test class code what you had written so far?
Thanks
@GM - You will have to call the controller methods in your test class explicitly to simulate user actions. Try this:
The assumption here is that - you have setup test data and the VFPage in the test class before calling the controller methods. Make sure you pass the right Id for the query parameters.
public class MultipleStdntView_TC
{
static testmethod void testLoadData()
{
Department__c dept = new department__c();
dept.Name = 'ECE';
insert dept;
Student__c s= new Student__c();
s.Name='Test';
S.Department__c = dept.id;
insert s;
system.currentpagereference().getparameters().put('id',dept.id);
MultipleStdntView1_AC mu=new MultipleStdntView1_AC();
mu.getdepartmentdetails();
/*MultipleStdntView1_AC.stdntlist sl= new MultipleStdntView1_AC.studentlist();
mu.getstudentdetails();*/
}
}
this is my test class i had written so far
@isTest
public class MultipleStdntView_TC
{
static testmethod void testLoadData()
{
Department__c dept = new department__c();
dept.Name = 'ECE';
insert dept;
Student__c s= new Student__c();
s.Name='Test';
S.Department__c = dept.id;
insert s;
system.currentpagereference().getparameters().put('id',dept.id);
MultipleStdntView1_AC mu=new MultipleStdntView1_AC();
mu.getdepartmentdetails();
/*MultipleStdntView1_AC.stdntlist sl= new MultipleStdntView1_AC.studentlist();
mu.getstudentdetails();*/
}
}
this is my test class sir
how we can call a "for loop" in test coverage sir
You mean how to cover a for loop in a test class?
For example .. how to cover that loop?
is your question
listOfAccounts = [SELECT id Name , BillingCity From Account WHERE BillingCity = 'India'];
for(Account act: listOfAccounts){
// some processing
}
Ans--In your test class insert some account records whose BillingCity = india;It will automatically cover that for loop.
suppose this is my for loop how can i cover this?
for(Account ac:ob)
{
inner class ic=new inner class();
ic.sno=count++;
ic.accountdetails=ac;
innerlist.add(ic);
}
Insert Account,
Add these line aslo
OuterClassName.InnserClassname clsObj = new OuterClassName.InnserClassname();
It will automatically cover.