You need to sign in to do that
Don't have an account?
How can I make my test class executable.?
Hello All,
-:Apex Class:-
public class Innerclass4List
{
public class fourlists
{
public List<Integer> firstlist ;
public List<Account> secondlist ;
public List<Opportunity> thirdlist ;
public List<String> fourthlist ;
}
public List<Account> selected (List<fourlists> FL)
{
return FL[0].secondlist;
}
}
-:Test Class:-
@isTest
public class testInnerclass4List
{
static testMethod void testmethodfourlist()
{
List<Innerclass4List.fourlists> testresultlist = new List<Innerclass4List.fourlists>();
Innerclass4List.fourlists ICF = new Innerclass4List.fourlists();
Account acct = new Account();
acct.Name = 'Ashok';
acct.AnnualRevenue = 10000;
acct.Phone = '0731467890';
ICF.secondlist.add(acct);
testresultlist.add(ICF);
Innerclass4List ICL = new Innerclass4List();
List<Account> secondlist = ICL.FL(testresultlist);
system.assert(secondlist.size()>0);
}
}
Where I went wrong; I can't figure it out. I need your help. Please Let me know if you are getting error.
Thank you all in advance
-:Apex Class:-
public class Innerclass4List
{
public class fourlists
{
public List<Integer> firstlist ;
public List<Account> secondlist ;
public List<Opportunity> thirdlist ;
public List<String> fourthlist ;
}
public List<Account> selected (List<fourlists> FL)
{
return FL[0].secondlist;
}
}
-:Test Class:-
@isTest
public class testInnerclass4List
{
static testMethod void testmethodfourlist()
{
List<Innerclass4List.fourlists> testresultlist = new List<Innerclass4List.fourlists>();
Innerclass4List.fourlists ICF = new Innerclass4List.fourlists();
Account acct = new Account();
acct.Name = 'Ashok';
acct.AnnualRevenue = 10000;
acct.Phone = '0731467890';
ICF.secondlist.add(acct);
testresultlist.add(ICF);
Innerclass4List ICL = new Innerclass4List();
List<Account> secondlist = ICL.FL(testresultlist);
system.assert(secondlist.size()>0);
}
}
Where I went wrong; I can't figure it out. I need your help. Please Let me know if you are getting error.
Thank you all in advance
I am not sure what you want to achieve functionally.
It seems that you have not initialzed the lists which are inside the wrapper class. Unless you initialse, memory would not be allocated at run time and hence I assume you are getting Attempt to De Reference.
I updated your code excerpt and it is giving me 100% Code Coverage. Let me know if this worked.
Important :
If you have received the answer which you are looking for, Please mark it as a Solution, this will help others to find the resolution of problem with ease. More, you can make the Developers of the Community smile by appreciating the answer with the "Like" Button. We would love to help you again.
Thank You
Gautam Singh
Blog - http://singhgautam02.blogspot.in/
Me - about.me/singhgautam
All Answers
Also, in the test class you have not inserted the test account record.
I am not sure what you want to achieve functionally.
It seems that you have not initialzed the lists which are inside the wrapper class. Unless you initialse, memory would not be allocated at run time and hence I assume you are getting Attempt to De Reference.
I updated your code excerpt and it is giving me 100% Code Coverage. Let me know if this worked.
Important :
If you have received the answer which you are looking for, Please mark it as a Solution, this will help others to find the resolution of problem with ease. More, you can make the Developers of the Community smile by appreciating the answer with the "Like" Button. We would love to help you again.
Thank You
Gautam Singh
Blog - http://singhgautam02.blogspot.in/
Me - about.me/singhgautam
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
Since you are new to technology I would recommend you to go through trailhead modules (hope you have heard of this :-) ) or any developer workbooks/tutorails regarding apex.
But I wanna know one thing; do tell me why are you inserting account in the test class, I don't need insert operation in my main method. do you have another way for the same.
The Account getting inserted is not getting into the Database. I am inserting the record in the test class.
Why do we need to insert record ? = Why do we do in a Test Class ?
Ans - Test classes are written to make an automated regrssive test coverage of your code. This makes sure that each of your conditions positive or negative are working properly. Now, in order to have code coverage of your code, you need to call your 'selected' method.
This 'selected' method requies a parameter of a list of accounts (wrapper instance). to have this list of accounts, you need to insert a dummy test class account record.
I believe you are completely new to test classes, I recommend you reading this (http://https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods" target="_blank). This will make you aware of test classes more easily.