function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ranadheer chRanadheer ch 

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
SonamSonam (Salesforce Developers) 
When you run this test in the developer console and open the class, it will show you the code lines which are not covered under test .

You can then create specific tests for only those lines to increase code ceverage.
Ranadheer chRanadheer ch
hI SONAM.........these lines  are not coverd in my code how to add these lines to my following test class....thanks in advanceUser-added image


and my class and testclass given mentioned in my question
SonamSonam (Salesforce Developers) 
As it is a get method , try to invoke the property arcs in your test method:

reference: http://stackoverflow.com/questions/9530326/how-can-i-test-a-get-method-in-my-controller