+ Start a Discussion
renuamirenuami 

help on custom controller test method

Hi

Finally learned how to write test methods. But it looks like the code coverage is not enough. I got 55% code coverage. Please giude me how to cover the rest.

When i run the tests i got the following lines are not covered. I am not getting any idea of how to write. please guide...thanks

 

Code Not Covered

 

Class

Travelling_Redirect

10

16

 

Class

Travelling_Redirect

12

21

 

Class

Travelling_Redirect

13

16

 

Class

Travelling_Redirect

14

21

 

Class

Travelling_Redirect

15

16

 

Class

Travelling_Redirect

16

21

 

Class

Travelling_Redirect

17

16

 

Class

Travelling_Redirect

19

16

 

Class

Travelling_Redirect

31

21

 

Class

Travelling_Redirect

33

25

 

Class

Travelling_Redirect

35

21

 

Class

Travelling_Redirect

36

21

 

Class

Travelling_Redirect

38

21

 

 

public class Travelling_Redirect
{
DateTime t;
List<Travelling__c> tvt;

public PageReference init()
{
User us=[Select TIMEZONESIDKEY from User where id=:UserInfo.getUserId()];
{
if(us.TIMEZONESIDKEY=='America/New_York' || us.TIMEZONESIDKEY=='America/Panama')
t=System.Now();
else if(us.TIMEZONESIDKEY=='America/Chicago' || us.TIMEZONESIDKEY=='America/El_Salvador')
t=System.Now()+1;
else if(us.TIMEZONESIDKEY=='America/Denver' || us.TIMEZONESIDKEY=='America/Phoenix')
t=System.Now()+2;
else if(us.TIMEZONESIDKEY=='America/Los_Angeles' || us.TIMEZONESIDKEY=='America/Tijuana')
t=System.Now()+3;
else
t=System.Now();
}
tvt=[select place, redemption_date__c from Travelling__c where expiration_date__c>=:t and SFDC_ID__c=:UserInfo.getUserId() limit 1];
Integer count= tvt.size();
return redirectTest(count,tvt);
}
public PageReference redirectTest(Integer count,List<Travelling__c> tvt)
{
PageReference myPR = null;
DateTime resu;
if(tvt.size()>0)
{
for(Travelling__c t:tvt)
{
resu=t. redemption_date__c;
}
if(resu==null)
myPR=Page.Travelling_Home;
else
myPR=Page. Travelling _AlreadySelected;
}
else
myPR = Page.Travelling_No_Places;

if (myPR != null)
myPR.setRedirect(true);
return myPR;
}


public static testMethod void results()
{
Travelling_Redirect test=new Travelling_Redirect();
test.init();
}
}

 

 

 

Message Edited by renuami on 04-15-2009 12:05 PM