+ Start a Discussion
Arun KArun K 

test class coverage

I am trying to write the test class.

 

In that I have below line

"public static Id acid {get;set;}"

 

which needs to be covered.

 

Please help me in covering the line.

 

Thanks in advacne

Arun K

Sagarika RoutSagarika Rout

As this is a static variable. so you can directly access this variable with your class name.

suppose your class name is

 

class ABC{

      public static Id acid {get;set;}

}

 

and you are define a test class as

@istest

public class testABC{

 

       public  static void ABC(){

             ABC.acid = "some data" ;

      }

}

 

 

 

Sagraika Rout

SFDC Developer

 

Arun KArun K

I have   "public static Id acid {get;set;}" in my test and I need to write system.assert();

 

Please guide me.

 

Thanks

Sagarika RoutSagarika Rout

Then directly you can access this variable . and you can use it in system.accert().

 

if you are still getting error please post your complete test class code .

 

 

 

Sagarika Rout

SFDC Developer

souvik9086souvik9086

You can populate like

ControllerName con = new ControllerName();

con.acid = //Give a valid object id to which you are referencing

Arun KArun K

Thanks,

This is my test class code..
"
@isTest
public class Test__Call_Plan_PC
{
private static Account objAcc;
private static user objuser;
private static user objuser1;
private static List<Account> objAccount ;
public static Id acid {get;set;}
public static testmethod void testmy()
{
LoadData();
CreateAccount();

ApexPages.StandardController sc= new ApexPages.StandardController(objuser);
ApexPages.currentPage().getParameters().put('userid', objuser.id);
apexpages.currentpage().getparameters().put('accid', acid);

Apexpages.currentPage().getParameters().put('firstname' , 'test');
Apexpages.currentPage().getParameters().put('lastname','test');
Apexpages.currentPage().getParameters().put('specialities','fm');
Apexpages.currentPage().getParameters().put('status','Original');
Apexpages.currentPage().getParameters().put('city','hyd');
Apexpages.currentPage().getParameters().put('original_calls','6');
Apexpages.currentPage().getParameters().put('Call_Status','New');

_CallPlan_Ctrl.wrapper wrap = new _CallPlan_Ctrl.wrapper();
wrap.selected = true;

_CallPlan_Ctrl cont = new _CallPlan_Ctrl();

_CallPlan_Ctrl contr= new _CallPlan_Ctrl(sc);
contr.getDroppedCount();
contr.getUpdated_Accounts();
contr.cancel_reset_to_original_confirm();
contr.cancel_reset_to_original();
contr.Reset_to_original();
contr.Resetall_confirm();
contr.Product_4_pde= 1;
contr.Product_1_pde=0;
contr.Resetall();
contr.undo();
contr.reset();
contr.setDisplayTable();
contr.setDisplayTablefalse();
contr.getCalls();
contr.getCalled_by_others();
contr.runSearch();
contr.SubmitCallplanacc();
contr.saveme();
contr.cancel();
contr.getTotal_Updated_Calls();
contr.getAbsolute_Calls_change();
contr.getUpdated_Calls_Percent();
contr.getchangedHTN_Per();
contr.getChangedProduct_4_Per ();
contr.getHTN_Per();
contr.getOrginal_HTN_Per();
contr.getProduct_1_Per ();
contr.getProduct_2_Per ();
contr.getProduct_3_Per ();
contr.getProduct_4_Per ();
contr.getOriginal_Product_1_Per();
contr.getOriginal_Product_2_Per();
contr.getOriginal_Product_3_Per();
contr.getOriginal_Product_4_Per();
contr.getProduct_4_Per();

contr.getUpdated_HTN_Pde();
contr.getPDE_low_limit();
contr.getPDE_high_limit();

contr.getGreen_Upper_limit();
contr.getGreen_Lower_limit();
contr.getRed_Upper_limit ();
contr.getRed_Lower_limit ();
contr.callPlanIndicators();
// contr.showpopup();
contr.RemoveFromCallplan();
contr.SubmitCallplanacc();




}
static testmethod void testmyh()
{
LoadData();

}

static void LoadData()
{
CreateUser();
CreateUser1();
system.runas(objuser1)
{
CreateAccount();
}
system.runas(objuser)
{
CreateAccount();
}

}

static void CreateAccount()
{
CreateUser();
objAccount = new List<Account>();
objAcc = new Account();
objAcc.Name = 'Test Account';
objAcc.Active__c='Yes';
objAcc.PHYSICIAN_ID__c = '1004';
objAcc.Specialization_differential__c='GP';
objAcc.Reason_Drop_Code__c='- Retired';
objAcc.Approval__c='Approved';
objAcc.DM_updated_flag__c=true;
objAcc.Billingstate='andhra pradesh';
objAcc.Notes__c ='test notes';

objAcc.Ownerid=UserInfo.getUserId();
objAcc.Original_Callplan_flag__c =false;
objAcc.Original_Universe_flag__c =true;


account objAcc1 = new Account();
objAcc1.Name = 'Test Account1';
objAcc1.Active__c='Yes';
objAcc1.PHYSICIAN_ID__c = '1004';
objAcc1.Specialization_differential__c='GP';
objAcc1.Reason_Drop_Code__c='- Retired';
objAcc1.Approval__c='Pending';
objAcc1.DM_updated_flag__c=true;
objAcc1.Billingstate='andhra pradesh';
objAcc1.Notes__c ='test notes';
objAcc1.Submit__c=True;

// objAcc1.Co_Owner__c=objuser.id;
objAcc1.Ownerid=UserInfo.getUserId();
objAcc1.Original_Callplan_flag__c =true;
objAcc1.Original_Universe_flag__c =false;

account objAcc12 = new Account();
objAcc12.Name = 'Test Account1';
objAcc12.Active__c='No';
objAcc12.PHYSICIAN_ID__c = '1005';
objAcc12.Specialization_differential__c='GP';
objAcc12.Reason_Add_Code__c='-Group Practice Physician';
objAcc12.Approval__c='Pending';
objAcc12.DM_updated_flag__c=true;
objAcc12.Billingstate='andhra pradesh';
objAcc12.Notes__c ='test notes';
objAcc12.Submit__c=True;


account objAcc13 = new Account();
objAcc13.Name = 'Test Account4';
objAcc13.Active__c='Yes';
objAcc13.PHYSICIAN_ID__c = '1005';
objAcc13.Specialization_differential__c='GP';
objAcc13.Reason_Drop_Code__c='- Retired';
objAcc13.Approval__c='Pending';
objAcc13.Reason_for_Drop_Flag__c=true;
objAcc13.DM_updated_flag__c=false;
objAcc13.Billingstate='andhra pradesh';
objAcc13.Notes__c ='test notes';
objAcc13.Submit__c=True;

account objAcc14 = new Account();
objAcc14.Name = 'Test Account4';
objAcc14.PHYSICIAN_ID__c = '1006';
objAcc14.Active__c='Yes';
objAcc14.Specialization_differential__c='GP';
objAcc14.Reason_Drop_Code__c='- Retired';
objAcc14.Approval__c='Pending';
objAcc14.Reason_for_Drop_Flag__c=true;
objAcc14.DM_updated_flag__c=false;
objAcc14.Billingstate='andhra pradesh';
objAcc14.Notes__c ='test notes';
objAcc14.Submit__c=false;


insert objAcc;
system.assertequals(objAcc.name,'Test Account');
acid=objAcc.id;
insert objAcc1;
system.assertequals(objAcc1.name,'Test Account1');
insert objAcc12;
system.assertequals(objAcc12.name,'Test Account1');
insert objAcc13;
system.assertequals(objAcc13.name,'Test Account4');
insert objAcc14;
system.assertequals(objAcc14.name,'Test Account4');
system.assertequals(acid,objAcc.id);

objAccount.add(objAcc);
objAccount.add(objAcc1);
objAccount.add(objAcc12);
objAccount.add(objAcc14);

Call_Sequence__c call=new Call_Sequence__c (Account__c=objAcc.id,CallSequence_Status__c ='New',Original_Calls__c =6,Primary__c='Arexone',Secondary__c='Methanel',Updated_Calls_plist__c='9');
insert call;
System.assertequals(call.CallSequence_Status__c,'New');

Call_Sequence__c call1=new Call_Sequence__c (Account__c=objAcc1.id,CallSequence_Status__c ='New',Original_Calls__c =9,Primary__c='Senetel',Secondary__c='Hectol',Updated_Calls_plist__c='12');
insert call1;
System.assertnotequals(call1.CallSequence_Status__c,'New1');
Call_Sequence__c call2=new Call_Sequence__c (Account__c = objAcc12.id,CallSequence_Status__c ='New',Original_Calls__c =9,Primary__c='Hectol',Secondary__c='Arexone',Updated_Calls_plist__c='15',prior_status__c='open',Original_Calls_flag__c=true,priorvalue__c='opentest');
insert call2;
System.assertequals(call2.CallSequence_Status__c,'New');
Call_Sequence__c call3=new Call_Sequence__c (Account__c=objAcc13.id,CallSequence_Status__c ='Pending',Original_Calls__c =9,Primary__c='Senetel',Secondary__c='Hectol',Updated_Calls_plist__c='3');
insert call3;
System.assertequals(call3.CallSequence_Status__c,'Pending');
Call_Sequence__c call4=new Call_Sequence__c (Account__c=objAcc14.id,CallSequence_Status__c ='Pending',Original_Calls__c =9,Primary__c='Senetel',Secondary__c='Effient',priorvalue__c = 'No change',Updated_Calls_plist__c='3');
insert call4;
System.assertnotequals(call4.CallSequence_Status__c,'New');

}
static void CreateUser()
{
Profile p = [SELECT Id FROM Profile WHERE Name='Sales Rep'];
objuser = new User(Alias = 'standt', Email='standarduser@axtria.com',Total_Calls__c=100,
EmailEncodingKey='UTF-8', LastName='ustr ', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id, department = 'STP',
TimeZoneSidKey='America/Los_Angeles', UserName=Math.random() + '@axtria.com',UserSubmit__c = false,Total_PDE__c=1012,Original_Accounts__c=40,Territory_Name__c='Lake Mary FL 3',Original_Plan_Sumbit_Flag__c = false,Rep_Type__c='Hectol-Hypertension',User_Status__c = '',Product_1_PDEs__c =60,Product_2_PDEs__c =70,Product_3_PDEs__c =80,Product_4_PDEs__c =50,Product_5_PDEs__c =0);
insert objuser;
System.assertequals(objuser.Alias,'standt');
}
static void CreateUser1()
{
Profile p1 = [SELECT Id FROM Profile WHERE Name='Sales Rep'];
objuser1 = new User(Alias = 'standt', Email='standarduser@axtria.com',Total_Calls__c=100,
EmailEncodingKey='UTF-8', LastName='ustr ', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p1.Id, department = 'STP',
TimeZoneSidKey='America/Los_Angeles', UserName=Math.random() + '@axtria.com',UserSubmit__c = true,Total_PDE__c=1012,Original_Accounts__c=40,Territory_Name__c='Lake Mary FL 2',Original_Plan_Sumbit_Flag__c = true,Rep_Type__c='Hectol-Hypertension',User_Status__c = 'pending',Product_1_PDEs__c =60,Product_2_PDEs__c =70,Product_3_PDEs__c =80,Product_4_PDEs__c =50,Product_5_PDEs__c =0);
insert objuser1;
System.assertequals(objuser1.Alias,'standt');
}
}"

Sagarika RoutSagarika Rout

Please use this

 

system.assertequals(Test__Call_Plan_PC.acid,objAcc.id);

 

I think it will work.

 

 

 

 

Regards

Sagarika Rout

SFDC Developer

Arun KArun K

con.acid = //Give a valid object id to which you are referencing

 

you mean valid id means "hard-coded record id "

souvik9086souvik9086

You can give hardcoded ID or by inserting an object record and referencing ID there.