+ Start a Discussion
viswadaviswada 

Need Test coverage

Hi  All,

 

  I have  a class , I have written Test class for that . I am Getting only 54%.   any one help to get &5 %

 

Class

-----------------

public class ideauser {

public list<AggregateResult> lstAr = new list<AggregateResult>();
public list<AggregateResult> lstAr1 = new list<AggregateResult>();
public list<Profile> pid = new list<Profile>();
public List<User> uid = new List<User>();

public ideauser()
{
pid = [select Id from Profile where name = 'Customer Portal Ideas User'];
//pid = [select Id from Profile where name = 'Themes Ideas Portal User'];
uid=[select Id from User where ProfileId IN :pid and LastLoginDate=this_week];
lstAr = [select CreatedBy.CommunityNickname Name, count(Id) Total from idea where CreatedDate=This_Week and CreatedById IN :uid group by CreatedBy.CommunityNickname order by count(Id) DESC limit 3];
lstAr1 = [select CreatedBy.CommunityNickname Name, count(Id) Total from IdeaComment where CreatedDate=This_Week and CreatedById IN :uid group by CreatedBy.CommunityNickname order by Count(Id) DESC limit 3];
}
public list<Ideaclass1> getResultsVotes()
{
list<Ideaclass1> lstResult1 = new list<Ideaclass1>();
for(AggregateResult ar1 : lstAr1)
{
Ideaclass1 objIdeaclass1 = new Ideaclass1(ar1);
lstResult1.add(objIdeaclass1);
}
return lstResult1;
}
public list<Ideaclass> getResults()
{
list<Ideaclass> lstResult = new list<Ideaclass>();
for(AggregateResult ar : lstAr)
{
Ideaclass objIdeaclass = new Ideaclass(ar);
lstResult.add(objIdeaclass);
}
return lstResult;
}

class Ideaclass
{
public Integer Total
{get;set;}
public String Name
{get;set;}

public Ideaclass(AggregateResult ar)
{
Total = (Integer) ar.get('Total');
Name = (String)ar.get('Name');
}
}
class Ideaclass1{
public Integer Total
{get;set;}
public String Name
{get;set;}

public Ideaclass1(AggregateResult ar1)
{
Total = (Integer) ar1.get('Total');
Name = (String)ar1.get('Name');
}

}

}

 

 

test class:

-----------------------

 

@istest

Private class Testideauser{
Private static testMethod void testideauser(){

idea id1=new idea(Tags__c='aaaaa',Status_Changed_By__c='3333',title='hiidea',CommunityId='09aE00000007RhMIAU');
insert id1;
idea id2=new idea(Tags__c='bbbbb',Status_Changed_By__c='aaaa',title='hiidea',CommunityId='09aE00000007RhMIAU');
insert id2;
idea id3=new idea(Tags__c='ccccc',Status_Changed_By__c='bbbb',title='hiidea',CommunityId='09aE00000007RhMIAU');
insert id3;
idea id4=new idea(Tags__c='adddddd',Status_Changed_By__c='rrrrrr',title='hiidea',CommunityId='09aE00000007RhMIAU');
insert id4;
idea id5=new idea(Tags__c='ssss',Status_Changed_By__c='zzzzz',title='hiidea',CommunityId='09aE00000007RhMIAU');
insert id5;
idea id6=new idea(Tags__c='yyyyy',Status_Changed_By__c='xxxx',title='hiidea',CommunityId='09aE00000007RhMIAU');
insert id6;
idea id7=new idea(Tags__c='zzzzzz',Status_Changed_By__c='yyyyy',title='hiidea',CommunityId='09aE00000007RhMIAU');
insert id7;

list<AggregateResult> lstAr = new list<AggregateResult>();
list<AggregateResult> lstAr1 = new list<AggregateResult>();
String Uid =UserInfo.getUserId() ;
lstAr = [select CreatedBy.CommunityNickname Name, count(Id) Total from idea where CreatedDate=This_Week and CreatedById =:uid group by CreatedBy.CommunityNickname order by count(Id) DESC limit 3];
lstAr1 = [select CreatedBy.CommunityNickname Name, count(Id) Total from IdeaComment where CreatedDate=This_Week and CreatedById =:uid group by CreatedBy.CommunityNickname order by Count(Id) DESC limit 3];
ideauser u = new ideauser();
u.getResultsVotes();
u.getResults();


}
}

 

The Red color code is not coveing , please help me

Best Answer chosen by Admin (Salesforce Developers) 
viswadaviswada

Thq ., Now I am Getting 77%.   Thank you very much

All Answers

PrakashbPrakashb

You need to do the below.

 

ideauser u = new ideauser();

 

u.lstAr = [select CreatedBy.CommunityNickname Name, count(Id) Total from idea where CreatedDate=This_Week and CreatedById =:uid group by CreatedBy.CommunityNickname order by count(Id) DESC limit 3];
u.lstAr1 = [select CreatedBy.CommunityNickname Name, count(Id) Total from IdeaComment where CreatedDate=This_Week and CreatedById =:uid group by CreatedBy.CommunityNickname order by Count(Id) DESC limit 3];


u.getResultsVotes();
u.getResults();

 

 

viswadaviswada

Thq ., Now I am Getting 77%.   Thank you very much

This was selected as the best answer