You need to sign in to do that
Don't have an account?

Code coverage is 73% How can I improve it?
code coverage is 73% What can I do to improve it?I was trying o deploy my code to the production org and failed as the code coverage is below 75%. Can someone suggest a way to improve my code coverage? Thanks!
Controller
public with sharing class contrller {
Public id Current_Acc_Id;
public contrller(ApexPages.StandardController controller) {
Current_Acc_Id = controller.getRecord().id;
}
public List<Contact> getrelatedContacts(){
List <contact> conList = New List<Contact>();
for(Account acc:[select id,name,(select name,email, phone, LastModifiedDate from contacts) from account where id=:Current_Acc_Id]){
for(contact con:acc.contacts)
conList.add(con);
}
return conList;
}
}
Test Class
@isTest(seeAllData=False)
private class Contrller_Test2{
static void setupData(){
Account testAccount = new Account(Name = 'Test', Chainname__c = '123', Chain_Code__c ='456', Company__c = '789');
insert testAccount;
Contact testcontact = new Contact ( LastName = 'Test', Account = testAccount);
insert testcontact;
}
static testMethod void getrelatedContacts(){
Account myAccount = [SELECT Id, Name FROM Account WHERE Name = 'Test' ];
List <contact> myconList = New List<Contact>();
for(Account acc:[select id,name,(select name,email, phone, LastModifiedDate from contacts) from account where id=:myAccount.id]){
for(contact con:acc.contacts)
myconList.add(con);
}
system.assertequals(1, myconlist.size());
}
}
Controller
public with sharing class contrller {
Public id Current_Acc_Id;
public contrller(ApexPages.StandardController controller) {
Current_Acc_Id = controller.getRecord().id;
}
public List<Contact> getrelatedContacts(){
List <contact> conList = New List<Contact>();
for(Account acc:[select id,name,(select name,email, phone, LastModifiedDate from contacts) from account where id=:Current_Acc_Id]){
for(contact con:acc.contacts)
conList.add(con);
}
return conList;
}
}
Test Class
@isTest(seeAllData=False)
private class Contrller_Test2{
static void setupData(){
Account testAccount = new Account(Name = 'Test', Chainname__c = '123', Chain_Code__c ='456', Company__c = '789');
insert testAccount;
Contact testcontact = new Contact ( LastName = 'Test', Account = testAccount);
insert testcontact;
}
static testMethod void getrelatedContacts(){
Account myAccount = [SELECT Id, Name FROM Account WHERE Name = 'Test' ];
List <contact> myconList = New List<Contact>();
for(Account acc:[select id,name,(select name,email, phone, LastModifiedDate from contacts) from account where id=:myAccount.id]){
for(contact con:acc.contacts)
myconList.add(con);
}
system.assertequals(1, myconlist.size());
}
}
below is the code that should be in your testmethod. replace <yourVF> with your VF page.
you can refer the link below on how to test controller and controller extn
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_error_handling.htm