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

getting code coverage of 63%, need help to increase the coverage
this is the apex class:
public class LocationWrapperClass
{
public Boolean checked{ get; set; }
public GE_PW_User_Sales_Hierarchy_Association__c cat { get; set;}
public string s {get;set;}
public LocationWrapperClass(){
cat = new GE_PW_User_Sales_Hierarchy_Association__c();
;
s = '';
}
public LocationWrapperClass(GE_PW_User_Sales_Hierarchy_Association__c c, String status){
cat = c;
;
s = status;
}
}
this is the test method which i wrote for above controller class: i'm getting 63% coverage only. help me to get good coverage
@isTest
private class Test_LocationWrapperClass
{
//**** This testMethod tests CategoryWrapper
public static testmethod void testLocationWrapperClass()
{
try
{
List<GE_PW_User_Sales_Hierarchy_Association__c> newTeamMembers;
User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
System.runAs ( thisUser )
{
//**** Get Profile record
Profile p = [select id from profile where Name = 'GE_PW WCMS Sales' limit 1];
//**** Get Role record
Userrole urAcc = [Select Id from UserRole where name like 'GE Water CMS Acct Mgr%' limit 1];
Userrole urArea = [Select Id from UserRole where name like 'GE Water CMS Area Mgr%' limit 1];
Userrole urDist = [Select Id from UserRole where name like 'GE Water CMS District Mgr%' limit 1];
Userrole urReg = [Select Id from UserRole where name like 'GE Water CMS Region Manager%' limit 1];
Userrole urPole = [Select Id from UserRole where name like 'GE Water CMS Pole Leader' limit 1];
List<Userrole> urList = new List<Userrole>();
urList.Add(urAcc);
urList.Add(urArea);
urList.Add(urDist);
urList.Add(urReg);
urList.Add(urPole);
//**** Insert test user records
List<User> lstUser = new List<User>();
for(Integer i = 0;i < 5 ;i++ )
{
User TestUser = new User(alias = 'standt', email = String.valueof(i)+'test@9876.com',
emailencodingkey = 'UTF-8', FirstName = 'TestFirstName' , lastname = 'TestLasName', languagelocalekey = 'en_US',
localesidkey = 'en_US', profileid = p.id ,UserRoleId = urList[i].Id,
timezonesidkey = 'America/Los_Angeles', username = String.valueof(i)+'test@9876.com');
//**** Add to user list
lstUser.add(TestUser);
}
//**** insert User List
RollupValues.IsNoTrigger = true;
insert lstUser;
//**** update Manager field
//List<User> lstMgrUser = new List<User>();
for(Integer j = 0; j < 4; j++)
{
lstUser[j].ManagerId = lstUser[j+1].Id;
}
RollupValues.IsNoTrigger = true;
update lstUser;
//**** Create Account
Account acc = new Account(Name = 'TestAccountName');
//**** Insert the object virtually
insert acc;
//**** Create AccountTeamMember Records
newTeamMembers = new List<GE_PW_User_Sales_Hierarchy_Association__c>();
GE_PW_User_Sales_Hierarchy_Association__c AccTeam = new GE_PW_User_Sales_Hierarchy_Association__c();
AccTeam.GE_PW_User_Id__c=lstUser[4].Id;
AccTeam.GE_PW_Location_Id__c='B39';
AccTeam.GE_PW_Parent_Location_Id__c='B56';
Accteam.GE_PW_Location_Level_Name__c='Region';
AccTeam.GE_PW_Parent_Location_Level_Name__c='Region';
AccTeam.GE_PW_Primary_Ownership_Flag__c = 'YES';
newTeamMembers.add(AccTeam);
AccTeam = new GE_PW_User_Sales_Hierarchy_Association__c();
AccTeam.GE_PW_User_Id__c=lstUser[3].Id;
AccTeam.GE_PW_Location_Id__c='B49';
AccTeam.GE_PW_Parent_Location_Id__c='B46';
Accteam.GE_PW_Location_Level_Name__c='Region';
AccTeam.GE_PW_Parent_Location_Level_Name__c='Region';
AccTeam.GE_PW_Primary_Ownership_Flag__c = 'NO';
newTeamMembers.add(AccTeam);
insert newTeamMembers;
//**** Start Test
Test.startTest();
LocationWrapperClass cw = new LocationWrapperClass();
System.assertEquals(cw.checked,false);
//**** Stop Test
Test.stopTest();
}}
catch(Exception e)
{
system.debug('Error Message:::: '+ e.getmessage());
system.assert(false,e.getmessage());
}
}
}
System.assertEquals(cw.s, 'Testing');
To
System.assertEquals(cw2.s, 'Testing');
All Answers
Presumably your multi-arg constructor is showing a lack of coverage?
You should be able to get coverage of this with a line or two:
hi i tried with the solution which you gave. Now i'm getting 100% code coverage but getting the test failure with exception message as System.AssertException: Assertion Failed: Expected: , Actual: Testing.... could you please help me why this is happening?
System.assertEquals(cw.s, 'Testing');
To
System.assertEquals(cw2.s, 'Testing');
ya got it.. i failed to notice that.. thanks