You need to sign in to do that
Don't have an account?
Test class for Apex class shows '0' lines not tested, 100% covered
Hi,
I wrote test class for apex class, when i run that test class it shows '0' lines not tested, 100% covered.
Apex class is:
public with sharing class CustomerRetirement
{
public CustomerRetirement(ApexPages.StandardController controller)
{
this.retirement= (Customer_Retirement_Detail__c)controller.getRecord();
updateRetirementDetails = getCustomerRetirement();
}
public CustomerRetirement(){}
List<Customer_Retirement_Detail__c> customerRetirementDetails;
private final List<Customer_Retirement_Detail__c> updateRetirementDetails;
private String educationGoalId;
private String customerId;
private String message=null;
public String getCustomerId()
{
return customerId;
}
public void setCustomerId(String customerId)
{
this.customerId=customerId;
}
public boolean isCustomerIdExit()
{
boolean isCustomerId=false;
List<Customer_Retirement_Detail__c> duplicateRetirementId=[select Customer_Id__c
from Customer_Retirement_Detail__c where Customer_ID__c = :retirement.Customer_Id__c];
for(Customer_Retirement_Detail__c retirement1:duplicateRetirementId)
if(retirement1.Customer_Id__c == retirement.Customer_Id__c)
{
isCustomerId=true;
}
else
{
isCustomerId=false;
}
return isCustomerId;
}
public PageReference cancelRecord()
{
PageReference page=null;
page = new PageReference('/apex/LifeInsuranceTab');
return page;
}
public PageReference save()
{
Integer p = 0;
ApexPages.Message myMsg=null;
try
{
String insuredPartyId=null;
boolean isCustomerId = isCustomerIdExit();
List<CustomerFinancialDetail__c> insuranceId =[select id from CustomerFinancialDetail__c
where Customer_Id__c =: retirement.Customer_Id__c];
for(CustomerFinancialDetail__c cfd : insuranceId)
{
insuredPartyId = cfd.id;
system.debug('******** Insured Party Id **********'+insuredPartyId);
}
if(isCustomerId == true)
{
message='Customer ID already in use';
myMsg = new ApexPages.Message(ApexPages.severity.ERROR,'Customer ID already in use','');
ApexPages.addMessage(myMsg);
}
else
{
retirement.Customer_Id__c=retirement.Customer_Id__c;
retirement.Financial_Detail__c = insuredPartyId;
retirement.Currency__c = retirement.Currency__c;
retirement.Annual_rate_at_retire_income_should_incr__c=retirement.Annual_rate_at_retire_income_should_incr__c;
retirement.Customer_s_retirement_year__c=retirement.Customer_s_retirement_year__c;
retirement.Max_Age__c=retirement.Max_Age__c;
retirement.Retire_income_payable_until_Age_year__c=retirement.Retire_income_payable_until_Age_year__c;
retirement.Retire_income_wanted_at_retirement_date__c=retirement.Retire_income_wanted_at_retirement_date__c;
retirement.Future_rate_of_Annual_price_inflation__c=retirement.Future_rate_of_Annual_price_inflation__c;
retirement.Desired_monthly_income_at_retirement__c=retirement.Desired_monthly_income_at_retirement__c;
retirement.Avg_rate_of_retire_income_for_Funded__c=retirement.Avg_rate_of_retire_income_for_Funded__c;
retirement.Purch_powertoday_s_desiredmonthly_income__c=retirement.Purch_powertoday_s_desiredmonthly_income__c;
retirement.Future_annualrate_ofreturn_oninvestments__c=retirement.Future_annualrate_ofreturn_oninvestments__c;
retirement.Age_at_which_the_plan_benefit_begins__c=retirement.Age_at_which_the_plan_benefit_begins__c;
retirement.Estimated_Plan_income_at_retirement__c=retirement.Estimated_Plan_income_at_retirement__c;
retirement.No_of_years_the_plan_benefit_is_paid__c=retirement.No_of_years_the_plan_benefit_is_paid__c;
retirement.A_R_O_rtrmt_income_incr_frm_these_plans__c=retirement.A_R_O_rtrmt_income_incr_frm_these_plans__c;
retirement.Plan_Beginning_Year__c=retirement.Plan_Beginning_Year__c;
retirement.Plan_Maturity_Year__c=retirement.Plan_Maturity_Year__c;
retirement.Plan_Current_Value__c=retirement.Plan_Current_Value__c;
retirement.Plan_Maturity_Value__c=retirement.Plan_Maturity_Value__c;
retirement.Rate_of_Increase_in_Plan_Value__c=retirement.Rate_of_Increase_in_Plan_Value__c;
retirement.Age_at_which_plan_benefit_begins__c=retirement.Age_at_which_plan_benefit_begins__c;
retirement.Plan_Annual_Contribution__c=retirement.Plan_Annual_Contribution__c;
retirement.Rate_of_incr_in_contributions_this_plan__c=retirement.Rate_of_incr_in_contributions_this_plan__c;
retirement.Estd_plan_annual_income_at_retirement__c=retirement.Estd_plan_annual_income_at_retirement__c;
retirement.No_of_years_plan_benefit_is_paid__c=retirement.No_of_years_plan_benefit_is_paid__c;
retirement.R_O_incm_rtrmt_plan_assumed_to_produce__c=retirement.R_O_incm_rtrmt_plan_assumed_to_produce__c;
retirement.Estd_plan_annual_incm_frm_G_p_s_at_rtrmt__c=retirement.Estd_plan_annual_incm_frm_G_p_s_at_rtrmt__c;
retirement.A_R_of_increase_in_income_for_govt__c=retirement.A_R_of_increase_in_income_for_govt__c;
retirement.E_P_Othr_income_frm_all_sources_at_rtrmt__c=retirement.E_P_Othr_income_frm_all_sources_at_rtrmt__c;
retirement.A_R_of_increase_in_income_for_other__c=retirement.A_R_of_increase_in_income_for_other__c;
retirement.Future_A_R_of_return_on_investment__c=retirement.Future_A_R_of_return_on_investment__c;
retirement.Plan_anual_income_frm_s_s_bnfts_at_rtrmt__c=retirement.Plan_anual_income_frm_s_s_bnfts_at_rtrmt__c;
retirement.Rate_of_increase_in_s_s_s_benefits__c=retirement.Rate_of_increase_in_s_s_s_benefits__c;
insert retirement;
p=2;
}
}
catch(Exception e)
{
p=1;
ApexPages.addMessages(e);
}
if(p==2)
{
message='Record Inserted Sucessfully';
myMsg = new ApexPages.Message(ApexPages.severity.CONFIRM,'Record Inserted Sucessfully','');
ApexPages.addMessage(myMsg);
}
return null;
}
public PageReference updateRecord()
{
ApexPages.Message myMsg=null;
try
{
Database.SaveResult[] sr = Database.update(updateRetirementDetails);
for(Database.SaveResult sr1 : sr)
if(sr1.isSuccess())
{
myMsg = new ApexPages.Message(ApexPages.severity.CONFIRM,'Record Saved Sucessfully','');
ApexPages.addMessage(myMsg);
}
}
catch(DmlException ex)
{
ApexPages.addMessages(ex);
}
return null;
}
public List<Customer_Retirement_Detail__c> getUpdateRetirementDetails()
{
return updateRetirementDetails;
}
public List<Customer_Retirement_Detail__c> getCustomerRetirement()
{
this.customerId = ApexPages.currentPage().getParameters().get('customerId');
customerRetirementDetails=[select Financial_Detail__c,
Customer_Id__c,Customer_Id__r.Name,Currency__c,Annual_rate_at_retire_income_should_incr__c,
Customer_s_retirement_year__c,Max_Age__c,Retire_income_payable_until_Age_year__c,
Retire_income_wanted_at_retirement_date__c,Future_rate_of_Annual_price_inflation__c,
Desired_monthly_income_at_retirement__c,Avg_rate_of_retire_income_for_Funded__c,
Purch_powertoday_s_desiredmonthly_income__c,Future_annualrate_ofreturn_oninvestments__c,
Age_at_which_the_plan_benefit_begins__c,Estimated_Plan_income_at_retirement__c,
No_of_years_the_plan_benefit_is_paid__c,A_R_O_rtrmt_income_incr_frm_these_plans__c,
Plan_Beginning_Year__c,Plan_Maturity_Year__c,
Plan_Current_Value__c,Plan_Maturity_Value__c,
Rate_of_Increase_in_Plan_Value__c,Age_at_which_plan_benefit_begins__c,Plan_Annual_Contribution__c,
Rate_of_incr_in_contributions_this_plan__c,Estd_plan_annual_income_at_retirement__c,
No_of_years_plan_benefit_is_paid__c,R_O_incm_rtrmt_plan_assumed_to_produce__c,
Estd_plan_annual_incm_frm_G_p_s_at_rtrmt__c,A_R_of_increase_in_income_for_govt__c,
E_P_Othr_income_frm_all_sources_at_rtrmt__c,A_R_of_increase_in_income_for_other__c,
Future_A_R_of_return_on_investment__c,Plan_anual_income_frm_s_s_bnfts_at_rtrmt__c,
Rate_of_increase_in_s_s_s_benefits__c,Defined_Benefit_or_Final_Salary_Plan__c,
Funded_Retirement_Plan__c,Government_Pension_Scheme__c,Income_from_assets__c,
Other_Income_During_Retirements__c,Social_Security_Benefits__c
from Customer_Retirement_Detail__c where Customer_ID__c = :customerId];
return customerRetirementDetails;
}
private final Customer_Retirement_Detail__c retirement;
}
I wrote test class is like this,
@isTest
private class CustomerRetirementTest
{
static testMethod void myUnitTest()
{
}
public static testmethod void testIsCustomerIdExit()
{
String duplicateRetirementId1='a0680000005zYu8';
List<Customer_Retirement_Detail__c> duplicateRetirementId=[select Customer_Id__c
from Customer_Retirement_Detail__c where Customer_ID__c = :duplicateRetirementId1];
for(Customer_Retirement_Detail__c retirement1:duplicateRetirementId)
system.assertEquals(retirement1.Customer_Id__c,duplicateRetirementId1);
}
public static testmethod void testCancelRecord()
{
String page='/apex/LifeInsuranceTab';
system.assertEquals(page,'/apex/LifeInsuranceTab');
}
public static testmethod void testSave()
{
Customer_Retirement_Detail__c crd=new Customer_Retirement_Detail__c();
crd.Customer_Id__c='a0680000005zYu8';
crd.Currency__c='$';
crd.Annual_rate_at_retire_income_should_incr__c=5;
crd.Customer_s_retirement_year__c=Date.newInstance(2035,09,02);
crd.Max_Age__c=60;
crd.Retire_income_payable_until_Age_year__c=60;
crd.Retire_income_wanted_at_retirement_date__c=1200000;
crd.Future_rate_of_Annual_price_inflation__c=15;
crd.Desired_monthly_income_at_retirement__c=25000;
crd.Avg_rate_of_retire_income_for_Funded__c=20;
crd.Purch_powertoday_s_desiredmonthly_income__c=15000;
crd.Future_annualrate_ofreturn_oninvestments__c=14;
crd.Age_at_which_the_plan_benefit_begins__c=26;
crd.Estimated_Plan_income_at_retirement__c=600000;
crd.No_of_years_the_plan_benefit_is_paid__c=24;
crd.A_R_O_rtrmt_income_incr_frm_these_plans__c=12;
crd.Plan_Beginning_Year__c='2004';
crd.Plan_Maturity_Year__c='2035';
crd.Plan_Current_Value__c=150000;
crd.Plan_Maturity_Value__c=750000;
crd.Rate_of_Increase_in_Plan_Value__c=18;
crd.Age_at_which_plan_benefit_begins__c=28;
crd.Plan_Annual_Contribution__c=45000;
crd.Rate_of_incr_in_contributions_this_plan__c=13;
crd.Estd_plan_annual_income_at_retirement__c=600000;
crd.No_of_years_plan_benefit_is_paid__c=14;
crd.R_O_incm_rtrmt_plan_assumed_to_produce__c=17;
crd.Estd_plan_annual_incm_frm_G_p_s_at_rtrmt__c=450000;
crd.A_R_of_increase_in_income_for_govt__c=14;
crd.E_P_Othr_income_frm_all_sources_at_rtrmt__c=170000;
crd.A_R_of_increase_in_income_for_other__c=15;
crd.Future_A_R_of_return_on_investment__c=13;
crd.Plan_anual_income_frm_s_s_bnfts_at_rtrmt__c=450000;
crd.Rate_of_increase_in_s_s_s_benefits__c=16;
}
}
Can any one help me, excpected code for line coverage and code coverage of 75%?
Thanks in Advance,
Thanks and Regards,
Srinivas Chittela
Hi ,
Try to create a Instance of class for which you want to cover the code...after that call method to execute the
code. .
for Example
Case cCase = new Case()
insert cCase;
ApexPages.StandardController sc = new ApexPages.StandardController(cCase);
CaseExtension caseExt = new CaseExtension(sc);
I think it will help you
Kirtesh
All Answers
Hi ,
Try to create a Instance of class for which you want to cover the code...after that call method to execute the
code. .
for Example
Case cCase = new Case()
insert cCase;
ApexPages.StandardController sc = new ApexPages.StandardController(cCase);
CaseExtension caseExt = new CaseExtension(sc);
I think it will help you
Kirtesh
Hi csrsak;
I'm sorry to ask but how do you say that you have written a test class for the class CustomerRetirement.
I can't see atleast one line of CustomerRetirement class is tested in the test class. Atleast you havn't create an instance of CustomerRetirement class in your test class.
In order to get a test coverage you have to call the methods in main class (CustomerRetirement) and test for the output result in the test class.
If you are new for test classes you could get an idea by looking at this very simple example.
http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=12061#M12061