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

I have created a test class but am getting only 57% coverd ...how to increase the code coverage
My class
public with sharing class AccountContactRoles {
private final Contact acr;
public AccountContactRoles(ApexPages.StandardController controller){
this.acr = (Contact)controller.getRecord();
}
public List<AccountContactRole> acrs {
get {
if (acrs == null) {
acrs = [Select Id, AccountId, ContactId, Role, IsPrimary From AccountContactRole
Where ContactId=:acr.Id];
}
return acrs;
}
private set;
}
}
my Test class
@isTest
private class TestAccountcontactroleClass{
@isTest
private static void testClass()
{
//Standard controller of Accountcontactrole
//Create a new instance of Accountcontactrole
Account acc = new Account(Name = 'Test Account');
insert acc;
Contact con = new Contact(LastName = 'Test Last Name', AccountId = acc.Id);
insert con;
AccountContactRole acr1 = new AccountContactRole();
acr1.AccountId = acc.Id;
acr1.ContactId = con.Id;
acr1.Role = 'Test 1';
acr1.IsPrimary=True;
insert acr1;
//Insert the object virtually
//Create a new instance of standard controller
ApexPages.StandardController sc = new ApexPages.standardController(con);
AccountContactRoles controller = new AccountContactRoles(sc);
}
}
Am getting the code coverage of 57% only...how to increase my code covrage for this class....Thanks in advance
public with sharing class AccountContactRoles {
private final Contact acr;
public AccountContactRoles(ApexPages.StandardController controller){
this.acr = (Contact)controller.getRecord();
}
public List<AccountContactRole> acrs {
get {
if (acrs == null) {
acrs = [Select Id, AccountId, ContactId, Role, IsPrimary From AccountContactRole
Where ContactId=:acr.Id];
}
return acrs;
}
private set;
}
}
my Test class
@isTest
private class TestAccountcontactroleClass{
@isTest
private static void testClass()
{
//Standard controller of Accountcontactrole
//Create a new instance of Accountcontactrole
Account acc = new Account(Name = 'Test Account');
insert acc;
Contact con = new Contact(LastName = 'Test Last Name', AccountId = acc.Id);
insert con;
AccountContactRole acr1 = new AccountContactRole();
acr1.AccountId = acc.Id;
acr1.ContactId = con.Id;
acr1.Role = 'Test 1';
acr1.IsPrimary=True;
insert acr1;
//Insert the object virtually
//Create a new instance of standard controller
ApexPages.StandardController sc = new ApexPages.standardController(con);
AccountContactRoles controller = new AccountContactRoles(sc);
}
}
Am getting the code coverage of 57% only...how to increase my code covrage for this class....Thanks in advance
You can then create specific tests for only those lines to increase code ceverage.
and my class and testclass given mentioned in my question
reference: http://stackoverflow.com/questions/9530326/how-can-i-test-a-get-method-in-my-controller