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
rajubalajirajubalaji 

how to overcome with test case was success but apex code coverage was zero

Hi everyOne,

I have written one test class while run it was showing success but while checking in apex class code coverage was zero.if any one have idea please guide me how to overcome with this issue.

Thanks InAdvance.

Regards,
Balaji
Nubes Elite Technologies Pvt. LtdNubes Elite Technologies Pvt. Ltd
Hi Balaji,

A quick solution for this :-
 
Open class in developer console, edit and save. Now class will show up in overall code coverage and we can see the colors that shows which lines are covered.

Thank You,
www.nubeselite.com
Development | Training | Consulting

Please mark this as solution if your problem is solved.
rajubalajirajubalaji
Hi Team,

Thank you so much for quick response.But it was not getting please find below apex class and test class please help me in this issue.

Apex Class:

@RestResource(urlMapping='/BulkPatientDeactivationResponse/*')
global class BulkPatientDeactivationResponse {
    @HttpPost
    global static void doPost() {
        if (RestContext.request.requestBody != null) {
            Savepoint sp = Database.setSavepoint();
            try {
                String environmentCode = Utility.getEnvironmentCode(UserInfo.getUserName());
                
                String reqBody = RestContext.request.requestBody.toString();
                if (reqBody.contains('Header')) {
                    TranRes res = (TranRes)JSON.deserialize(reqBody, BulkPatientDeactivationResponse.TranRes.class);
                    String fileName = 'Unknown', type = 'Unknown', status = 'Unknown';
                    if (res.Response.Header.FileID != null) {
                        fileName = res.Response.Header.FileID;
                    }
                    if (res.Response.Header.TransactionType != null) {
                        type = res.Response.Header.TransactionType;
                    }
                    if (res.Response.Header.Status != null) {
                        status = res.Response.Header.Status;
                    }
                    List<TransactionDetail__c> tranList = [select Id, Transaction_Status__c, Response_JSON__c, HUB_Practice__c, HUB_Provider__c, Comments__c, Request_JSON__c from TransactionDetail__c where FileID__c = :fileName and Name = :type Limit 1];
                    
                    if (res.Response.ResponseType.AccountCode != null && res.Response.ResponseType.AccountCode != '') {
                        List<Account> lstAccount = [Select Id, Model_Number__c from Account where BluestarId__c =: res.Response.ResponseType.AccountCode and Enviornment_Code__c = :environmentCode Limit 1];
                        if (lstAccount.size() > 0) {
                            TransactionDetail__c transDetail = tranList.get(0);
                            BulkPatientDeactivationController.BulkPatientDeactivation bulkPatientDeactivationUser = (BulkPatientDeactivationController.BulkPatientDeactivation)JSON.deserialize(transDetail.Request_JSON__c, BulkPatientDeactivationController.BulkPatientDeactivation.class);
                            
                            if (res.Response.ResponseType.SuccessUsers != null && res.Response.ResponseType.SuccessUsers != '') {
                                Attachment file = new Attachment();
                                file.name = bulkPatientDeactivationUser.Request.Patient.Data + '-SuccessBulkDeactivationUsers' + '.json';
                                file.parentId = lstAccount[0].Id;
                                file.body = Blob.valueOf(res.Response.ResponseType.SuccessUsers);
                                insert file;
                                
                                String successUsersContent = '{"User":' + res.Response.ResponseType.SuccessUsers + '}';
                                Users successUsers = (Users)JSON.deserialize(successUsersContent, BulkPatientDeactivationResponse.Users.class);
                                Integer userCount = successUsers.User.size();
                                
                                List<String> lstBlueStarIDs = new List<String>();
                                for (Integer i = 0; i < userCount; i++) {
                                    lstBlueStarIDs.Add(successUsers.User[i].BlueStarID + '__' + environmentCode);
                                }
                                
                                List<Hub_Patient__c> lstPatients = [select Id, BlueStarID__c from Hub_Patient__c where BlueStarID__c in :lstBlueStarIDs];
                                
                                List<Hub_Patient__c> lstPatientsToDeactivate = new List<Hub_Patient__c>();
                                List<Id> deactivationPatients = new List<Id>();
                                for (Hub_Patient__c usr:lstPatients){
                                    deactivationPatients.Add(usr.Id);
                                    
                                    //Update Patient Status
                                    usr.Product_Status__c = 'Inactive';
                                    usr.ProductStatusReason__c = bulkPatientDeactivationUser.Request.Patient.DeactivateReason;
                                    usr.Status__c = Label.HubStat_Inactive;
                                    lstPatientsToDeactivate.Add(usr);
                                }
                                                                
                                //CheckAndCloseAllTaskForPatients
                                List<Task> lstTask = [select Id, Type, Status from Task where WhatId in :deactivationPatients and Type != :Label.TaskType_PatientDrivenFailure and Status != 'Closed'];
                                if (lstTask.size() > 0) {
                                    for (Integer j = 0; j < lstTask.size(); j++) {
                                        lstTask[j].Status = 'Closed';
                                    }
                                    update lstTask;
                                }
                                
                                List<TransactionDetail__c> lstTran = new List<TransactionDetail__c>();
                                if (lstPatientsToDeactivate.size() > 0) {
                                    List<Database.SaveResult> lstResult = Database.update(lstPatientsToDeactivate, false);
                                    for (Integer i = 0; i < lstResult.size(); i++) {
                                        if (!lstResult[i].isSuccess()) {
                                            String message = null;
                                            Database.Error[] errs = lstResult[i].getErrors();
                                            for (Integer j = 0; j < errs.size(); j++){
                                                message = message + '\\n' + errs[j].getStatusCode() + ': ' + errs[j].getMessage() + '.'; 
                                            }
                                            TransactionDetail__c tran = new TransactionDetail__c();
                                            tran.Name = 'BulkPatientDeactivationFailure';
                                            tran.Transaction_Type__c = 'Inbound';
                                            tran.Transaction_Status__c = 'Exception';
                                            tran.Account__c = lstAccount[0].Id;
                                            tran.Request_JSON__c = JSON.serialize(successUsers.User[i]);
                                            tran.Response_JSON__c = message;
                                            lstTran.add(tran);
                                        }
                                    }
                                }
                                if (lstTran.size() > 0) {
                                    Database.insert(lstTran, false);
                                }
                            }
                            
                            if (res.Response.ResponseType.FailureUsers != null && res.Response.ResponseType.FailureUsers != '') {
                                Attachment file = new Attachment();
                                file.name = bulkPatientDeactivationUser.Request.Patient.Data + '-FailureBulkDeactivationUsers' + '.json';
                                file.parentId = lstAccount[0].Id;
                                file.body = Blob.valueOf(res.Response.ResponseType.FailureUsers);
                                insert file;
                                
                                TransactionDetail__c tran = new TransactionDetail__c();
                                tran.Name = 'BulkPatientDeactivationFailure';
                                tran.Transaction_Type__c = 'Inbound';
                                tran.Transaction_Status__c = 'Exception';
                                tran.Account__c = lstAccount[0].Id;
                                tran.Request_JSON__c = 'Error Deactivating Users in product. Error Deactivation Users details : ' + res.Response.ResponseType.FailureUsers;
                                tran.Response_JSON__c = 'Error Deactivating Users in product.';
                                Database.insert(tran);
                            }
                        }
                    }
                    
                    if (tranList.size() > 0) {
                        TransactionDetail__c tran = tranList[0];
                        tran.Transaction_Status__c = status;
                        tran.Response_JSON__c = reqBody;
                        update tran;
                    }
                    else {
                        BlueStarTransactionDetails.CreateUnknownTransactionResponse(fileName, status, reqBody);
                    }
                }
                else if (reqBody.contains('SchemaError')) {
                    SchemaErrorTran schemaErr = (SchemaErrorTran)JSON.deserialize(reqBody, BulkPatientDeactivationResponse.SchemaErrorTran.class);
                    System.debug(schemaErr);
                    if (schemaErr.Response.SchemaError.FileName != null) {
                        String fileName = schemaErr.Response.SchemaError.FileName.replace('SD_WD_', '').replace('_', '.').replace('.xml', '');
                        String tranStatus = 'Failure: ';
                        if (schemaErr.Response.SchemaError.ErrorText != null) {
                            if (schemaErr.Response.SchemaError.ErrorText.length() > 23) {
                                tranStatus = tranStatus + schemaErr.Response.SchemaError.ErrorText.substring(0, 22);
                            }
                            else {
                                tranStatus = tranStatus + schemaErr.Response.SchemaError.ErrorText;
                            }
                        }
                        List<TransactionDetail__c> tranList = [select Id, Transaction_Status__c, Response_JSON__c from TransactionDetail__c where FileID__c = :fileName Limit 1];
                        if (tranList.size() > 0) {
                            TransactionDetail__c tran = tranList[0];
                            tran.Transaction_Status__c = tranStatus;
                            tran.Response_JSON__c = reqBody;
                            update tran;
                        }
                        else {
                            BlueStarTransactionDetails.CreateUnknownTransactionResponse(schemaErr.Response.SchemaError.FileName, tranStatus, reqBody);
                        }
                    }
                    else {
                        BlueStarTransactionDetails.CreateUnknownTransactionResponse('Unknown', 'Unknown', reqBody);
                    }
                }
                else {
                    BlueStarTransactionDetails.CreateUnknownTransactionResponse('Unknown', 'Unknown', reqBody);
                }
            } catch (Exception ex) {
                Database.rollback(sp);
                String resp = RestContext.request.requestBody.toString();
                BlueStarTransactionDetails.CreateErrorProcessingTransactionResponse('Unknown', 'Exception', resp, ex.getMessage());
            }
        }
    }
    
    public class TranHeader {
        public String TransactionType;
        public String TimeStamp;
        public String FileID;
        public String Status;
    }
    
    public class ResType {
        public String HubCode {get;set;}
        public String BlueStarID {get;set;}
        public String AccountCode {get;set;}
        public String SuccessUsers {get;set;}
        public String FailureUsers {get;set;}
        public String FailedUsers {get;set;}
    }
    
    public class TranResp {
        public TranHeader Header;
        public ResType ResponseType;
    }
    
    public class TranRes {
        public TranResp Response;
    }
    
    public class SchemaErr {
        public String FileName {get;Set;}
        public String ErrorText {get;set;}
    }
    
    public class SchemaErrorResp {
        public SchemaErr SchemaError;
    }
    
    public class SchemaErrorTran {
        public SchemaErrorResp Response;
    }
    
    public class Users {
        List<DeactivationUser> User {get;set;}
    }
    
    public Class DeactivationUser {
        String Email {get;set;}
        String BlueStarID {get;set;}
    }
}
 
rajubalajirajubalaji
Hi Team,

And please find below test class for above apex class.

@isTest
Global class BulkPatientDeactivationResponseTest {
    
  @isTest
  static void testHttpPost(){
          
        RestRequest req = new RestRequest();
          RestResponse Res = new RestResponse();
        req.requestURI ='/services/apexrest/BulkPatientDeactivationResponse';
        req.httpMethod = 'POST';
      
        RestContext.request = req;
          RestContext.Response = res;
      
          Test.startTest();
              String actual = null;
          Test.stopTest();
       }
    
        static testMethod void testChangePatientStatusController(){
        createCustomSettings();
        Test.startTest();
        ChangePatientStatusController controller = new ChangePatientStatusController();
        Hub_Patient__c p = getMockPatientObject();
        String msg = controller.MoveStatus(p.Id);
        Test.stopTest();
    }
    
    static testMethod void testChangePatientStatusController6(){
        createCustomSettings();
        Test.startTest();
        ChangePatientStatusController controller = new ChangePatientStatusController();
        Hub_Patient__c p = getMockPatientObject();
        p.Status__c = Label.HubStat_BIPending;
        update p ;
        controller.MoveStatus(p.Id);
        
        p.Status__c = Label.HubStat_PendingTriage;
        p.TriageDocumentCount__c = 1; 
        update p;
        controller.MoveStatus(p.Id);
        
        Test.stopTest();
    }
    
    static testMethod void testChangePatientStatusController4(){
        createCustomSettings();
        Test.startTest();
        ChangePatientStatusController controller = new ChangePatientStatusController();
        Hub_Patient__c p = getMockPatientObject();
        p.Status__c = Label.HubStat_PAP;
        update p;
        controller.MoveStatus(p.Id);
        Test.stopTest();
    }
    
    static testMethod void testChangePatientStatusController2(){
        createCustomSettings();
        Test.startTest();
        ChangePatientStatusController controller = new ChangePatientStatusController();
        Hub_Patient__c p = getMockPatientObject();
        p.TriageDocumentCount__c = 1; 
        p.Status__c = Label.HubStat_PendingTriage;
        update p;
        controller.MoveStatus(p.Id);
        
        p.Status__c = Label.HubStat_TestClaim;
        update p;
        controller.MoveStatus(p.Id);
        Test.stopTest();
    }
    
    static testMethod void testFailedTransactionEmailController(){
        createCustomSettings();
        Test.startTest();
        TransactionDetail__c tran = new TransactionDetail__c();
        tran.Name = 'TransactionName';
        tran.TransactionFileId__c = 'TransactionFileId';
        tran.Transaction_Type__c = 'Inbound';
        tran.Transaction_Status__c = 'Failure';
        tran.Request_JSON__c = 'RequestJSON';
        tran.Response_JSON__c = 'ResponseJSON';
        tran.Patients__c = getMockPatientObject().id;
        insert tran;
        FailedTransactionEmailController controller = new FailedTransactionEmailController();
        controller.sendEmail();
        Test.stopTest();
    }    
    static testMethod void testCreatePatientEnrollment(){
        Test.startTest();
        createCustomSettings();
        MultiStaticResourceCalloutMock multimock = new MultiStaticResourceCalloutMock();
        Default_Settings__c settings = Default_Settings__c.getInstance('Configuration Values'); 
        multimock.setStaticResource(settings.Security_Token_URL__c, 'MockResponseGetToken');
        multimock.setStaticResource(settings.Base_URL__c + System.label.PatientEnrollment, 'MockResponseCreateEnrollment');
        multimock.setStatusCode(200);
        multimock.setHeader('Content-Type', 'application/json');
        Test.setMock(HttpCalloutMock.class, multimock);
        Hub_Patient__c p = getMockPatientObject();
        //CreateEnrollment(String patientID, String HubCode, String GivenName, String FamilyName, Date DOB, String Gender, String Email, String PatientProviderId, String PatientPracticeId, String PatientPracticeAddressId, String Prefix, String Suffix, String GivenName2)
        CreatePatientEnrollment.CreateEnrollment(p.Id,p.SampleCode__c,p.GivenName__c,p.FamilyName__c,p.DOB__c,p.Gender__c,p.Email__c,p.Provider__c,p.Practice__c,p.Practice_Address__c,p.Prefix__c, p.Suffix__c,p.GivenName2__c,'bst');
        CreatePatientEnrollment.getDateStringForMedicalHistory(System.today());
        Test.stopTest();
    }
    
    public static void createCustomSettings() {
        Default_Settings__c settings = new Default_Settings__c();
        settings.Name = 'Configuration Values';
        settings.AutomatedFollowUpTaskCreationDays__c = 1;
        settings.Base_URL__c = 'https://dev4-dsm.testwd.com/ProductSupport/api/protected/';
        settings.CoolOffTimeInDays__c = 0;
        settings.DefaultSettingUploadId__c = 'test1';
        settings.Has_Pending_Transaction_In_Min__c = 2;
        settings.No_Pending_Transaction_In_Min__c = 2;
        settings.PrescriptionRenewalNoticeDays__c = 20;
        settings.Security_Token_URL__c = 'https://dev4-dsm.testwd.com/SecurityTokenService/token';
        settings.TicketEscalationTimeInHours_Critical__c = 0;
        settings.TicketEscalationTimeInHours_High__c = 96;
        settings.TicketEscalationTimeInHours_Low__c = 240;
        settings.TicketEscalationTimeInHours_Medium__c = 160;
        settings.Token_Request_Body__c = 'grant_type=client_credentials&client_id=watthe3&client_secret=123acv';
        settings.Transaction_retry_time_in_minutes__c = 60;
        //String trainerAdminPermissionSetID = [Select Id from PermissionSet where Name = 'Trainer_Admin' Limit 1].Id;
        //User trainerAdminUser = [SELECT Id from User where IsActive = true and Id in (select AssigneeId from PermissionSetAssignment where PermissionSetId = :trainerAdminPermissionSetID) Limit 1];
        User trainerAdminUser = [SELECT Id from User where IsActive = true Limit 1];
        //String taskUser = [Select Id, Profile.Name, IsActive from User where Profile.Name = 'Trainer Admin' and IsActive = true Limit 1].Id;
        String taskUser = trainerAdminUser.id;
        settings.Obtain_Approval_Task_User__c = taskUser;
        
        settings.Due_Date_For_Complete_SRF_Task__c = 0;
        settings.Due_Date_For_Complete_BI_Task__c = 7;
        settings.Due_Date_For_Complete_Triage_Task__c = 0;
        settings.Due_Date_For_Investigate_PAP_Task__c = 3;
        settings.Due_Date_For_Complete_PA_Task__c = 0;
        settings.Due_Date_For_Obtain_Prescription_Task__c = 0;
        settings.Due_Date_For_Obtain_SRF_Task__c = 0;
        settings.Due_Date_For_Dispense_Denied_Task__c = 3;
        settings.Due_Date_For_Dispense_Failed_Task__c = 3;
        settings.Due_Date_For_Dispense_changed_Task__c = 0;
        settings.Due_Date_For_Fix_Data_Error_Task__c = 0;
        settings.Due_Date_For_PTR_Task__c = 0;
        settings.Due_Date_For_Obtain_Approval_Task__c = 0;
        settings.Due_Date_For_PatientDrivenFailure_Task__c = 0;
        settings.Due_Date_For_PatientDrivenSuccess_Task__c = 0;
        settings.Due_Date_For_20_day_Follow_Up_Task__c = 0;
        settings.Due_Date_For_Register_Patient_Task__c = 0;
        settings.PAP_Validation_Start_Year__c = 2016;
        settings.Failed_Transactions_Email_Ids__c = 'mkatekhaye@welldocinc.com,vshivashankar@welldocinc.com';
        insert settings;
    }
    
    public static Hub_Patient__c getMockPatientObject(){
        
        Integer count = 0;
        Hub_Patient__c patient = new Hub_Patient__c();

        Id wd_OppRecTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('WD Operations').getRecordTypeId();

        Account acc  = new Account(); 
        acc.Name = 'WellDoc';
        acc.BluestarId__c = 'WD';
        acc.Access_Type__c = 'ImmediateAccess';
        acc.Payment_Type__c = 'PaidByInsurance';
        acc.Sample_Code_Required__c = true;
        acc.Enviornment_Code__c = 'bst';
           acc.Country__c = 'UnitedStates';
        acc.Language__c = 'English';
        acc.First_Follow_Up_Task_In_Day_s__c = 3;
        acc.Second_Follow_Up_Task_In_Day_s__c = 20;
        acc.RecordTypeId = wd_OppRecTypeId;
        acc.User_Engagement_Days_Regd__c = 35;
        acc.User_Engagement_Days__c = 7;
        acc.Inactive_User_Task_due_days__c = 0;
        acc.Inactive_User_Task_Count__c = 4;
        acc.Active_User_Task_Creation_Day__c = 20;
        acc.Active_User_Task_due_days__c = 0;
        acc.Inactive_User_Task_Count__c = 2;
        acc.Inactive_User_Task__c = true;
        acc.Active_User_Task__c = true;
        
        insert acc;
        patient.AccountID__c = acc.Id;     
        
        patient.GivenName__c = 'Mangesh';
        patient.SampleCode__c = 'Sample' + String.valueOf(count);
        patient.FamilyName__c = 'K';
        patient.Status__c = 'SRF Incomplete';
        patient.BlueStarID__c ='BlueStarId__bst';
        patient.FamilyName__c = 'K';
        patient.DOB__c = System.today();
        patient.Gender__c = 'M';
        patient.Email__c = 'mkatekhaye@yahoo.com';
        patient.GivenName2__c = 'H';
        patient.Prefix__c = 'Mr.';
        patient.Suffix__c = 'Jr.';
        patient.Prescriber_Signed__c = true;
        patient.SRF_Received_Date__c = System.today();
        patient.Prescriber_Signed_Date__c = System.today();
        patient.Copay_Assistance_Applicable__c = 'Yes';
        patient.Enviornment_Code__c = acc.Enviornment_Code__c;
        //patient.OwnerId = UserInfo.getUserId();
        
        //Create Provider
        HUB_Provider__c provider = new HUB_Provider__c();
        provider.Name = '1234567899';
        provider.First_Name__c = 'Test';
        provider.Last_Name__c = 'Provider';
        insert provider;
        
        //Create Practice
        HUB_Practice__c practice = new HUB_Practice__c();
        practice.Name = 'Test Practice';
        practice.Type__c = 'Practice';
        insert practice;
        
        //Create Practice Address
        HUB_Practice_Address__c practiceAddress = new HUB_Practice_Address__c();
        practiceAddress.Address_Type__c = 'Work';
        practiceAddress.Address_1__c = 'Address1';
        practiceAddress.Address_2__c = 'Address1';
        practiceAddress.Zip_Code__c = '21202';
        practiceAddress.State__c = 'MD';
        practiceAddress.City__c = 'Baltimore';
        practiceAddress.Fax__c = '1234567899';
        practiceAddress.Phone_1__c = '1234567890';
        practiceAddress.Phone_1_Type__c = 'Home';
        practiceAddress.Phone_2__c = '1234567899';
        practiceAddress.Phone_2_Type__c = 'Work';
        
        practiceAddress.HUB_Practice__c = practice.Id;
        insert practiceAddress;
        
        patient.Provider__c = provider.id;
        patient.Practice__c = practice.id;
        patient.Practice_Address__c = practiceAddress.id;
        
        // insert patient;
        insert patient;
        
        //Create Prescription
        PatientPrescription__c prescription = new PatientPrescription__c();
        prescription.Prescription_Type__c = 'Original SRF';
        prescription.NumberOfFillWritten__c = 1;
        prescription.Refills_Writter__c = 11;
        prescription.Prescriber_Signed_Date__c = System.today();
        prescription.FillDate__c = System.today();
        prescription.RxNumber__c = 'Rx123';
        prescription.RefillsLeft__c = 12;
        prescription.Patients__c = patient.Id;
        
        insert prescription;
        
        Clinical_Data__c cData = new Clinical_Data__c();
        cData.Patients__c = patient.id;
        cData.A1C_Target__c = '<7';
        cData.A1C__c = 8;
        cData.A1C_Date__c = System.today();
        cData.BP_systolic__c = 120;
        cData.BP_diastolic__c = 90;
        cData.BP_Date__c = System.today();
        cData.Cardiovascular_Disease__c = true;
        cData.Serum_Creatinine__c = 25;
        cData.Serum_Creatinine_Date__c = System.today();
        cData.HDL__c = 10;
        cData.HDL_Date__c = System.today();
        cData.Hypertension__c = true;
        cData.Hyperlipidemia__c = true;
        cData.LDL__c = 10;
        cData.LDL_Date__c = System.today();
        cData.Trig__c = 12;
        cData.Trig_Date__c = System.today();
        cData.Urine_Microalbumin_Creatinine_Ratio__c = 2;
        cData.Urine_Microalbumin_Creatinine_Ratio_Date__c = System.today();
        cData.Height__c = 110;
        cData.Height_Date__c = System.today();
        cData.Weight__c = 50;
        cData.Weight_Date__c = System.today();
        insert cData;
        
        PatientAddress__c pAddress = new PatientAddress__c();
        pAddress.Address_1__c = 'Address1';
        pAddress.Address_2__c = 'Address1';
        pAddress.Address_3__c = 'Address1';
        pAddress.Address_Type__c = 'Home';
        pAddress.City__c = 'Baltimore';
        pAddress.State__c = 'MD';
        pAddress.Country__c = 'United States';
        pAddress.Zip_Code__c = '21202';
        pAddress.Primary_Address__c = true;
        pAddress.Patients__c = patient.id;
        insert pAddress;
        
        PatientPhoneNumber__c phoneNumber = new PatientPhoneNumber__c();
        phoneNumber.Phone_Type__c = 'Home';
        phoneNumber.Phone_Number__c = '1234567899';
        phoneNumber.Patients__c = patient.id;
        insert phoneNumber;
        
        Payer__c payer = new Payer__c();
        payer.Company_Name__c = 'WellDoc';
        payer.Name = 'My Payer';
        payer.Payer_Type__c = 'Type';
        insert payer;
        
        InsurancePlan__c insurancePlan = new InsurancePlan__c();
        insurancePlan.Name = 'My Plan';
        insurancePlan.Plan_Type__c = 'Medicare';
        insurancePlan.Payer_Name__c = payer.Id;
        insert insurancePlan;
        
        InsurancePlan__c insurancePlanPBM = new InsurancePlan__c();
        insurancePlanPBM.Name = 'My PBM';
        insurancePlanPBM.Plan_Type__c = 'PBM';
        insurancePlanPBM.Payer_Name__c = payer.Id;
        insert insurancePlanPBM;
        
        PatientInsurance__c insurance = new PatientInsurance__c();
        insurance.Insurance_Plan_Name__c = insurancePlan.id;
        insurance.Insurance_Type__c = 'Primary';
        insurance.Cardholder_ID__c = '1';
        insurance.Cardholder_DOB__c = System.today().format();
        insurance.Med_Coverage__c = 'Yes';
        insurance.Relationship_to_Cardholder__c = 'Self';
        insurance.Medical_Group_Number__c = '123';
        insurance.Med_Coverage__c = 'Yes';
        
        
        insurance.Rx_Drug_Card_ID__c = '123';
        insurance.PBM_Name__c = insurancePlanPBM.id;
        insurance.PBM_Group_Number__c = '345';
        insurance.BIN_Number__c = '123456';
        insurance.PCN__c = '111';
        insurance.BS_Coverage__c = 'Yes';
        insurance.Tier_Level__c = 'Level 2';
        insurance.Applicable_for_Triage__c = true;
        insurance.MedicalBenifitsApplicable__c = 'Yes';
        insurance.Patient__c = patient.id;
        insert insurance;
        
        PatientInsurance__c insuranceSecondary = new PatientInsurance__c();
        insuranceSecondary.Insurance_Plan_Name__c = insurancePlan.id;
        insuranceSecondary.Insurance_Type__c = 'Secondary';
        insuranceSecondary.Cardholder_ID__c = '1';
        insuranceSecondary.Cardholder_DOB__c = System.today().format();
        insuranceSecondary.Med_Coverage__c = 'Yes';
        insuranceSecondary.Relationship_to_Cardholder__c = 'Self';
        insuranceSecondary.Medical_Group_Number__c = '123';
        insuranceSecondary.Med_Coverage__c = 'Yes';
        
        insuranceSecondary.Rx_Drug_Card_ID__c = '123';
        insuranceSecondary.PBM_Name__c = insurancePlanPBM.id;
        insuranceSecondary.PBM_Group_Number__c = '345';
        insuranceSecondary.BIN_Number__c = '123456';
        insuranceSecondary.PCN__c = '111';
        insuranceSecondary.BS_Coverage__c = 'Yes';
        insuranceSecondary.Tier_Level__c = 'Level 2';
        insuranceSecondary.Applicable_for_Triage__c = true;
        insuranceSecondary.MedicalBenifitsApplicable__c = 'Yes';
        insuranceSecondary.Patient__c = patient.id;
        insert insuranceSecondary;
        
        count++;
        return patient;
    }
    private class myMock implements HttpCalloutMock {

        public HTTPResponse respond(HTTPRequest req) {
            HTTPResponse res = new HTTPResponse();
            res.setBody('<wREPLY payloadID="1234" timestamp="20191014" version="1.1"><Response><Status code="200" text="OK"/></Response></wREPLY>');
            res.setStatusCode(200);
            return res;
        }
}
}

Thanks inadvance
Ajay K DubediAjay K Dubedi
Hi Balaji Karthik,

    If you are trying to execute a trigger then please check that your Trigger is active 
    because your code has zero% Coverage that means your trigger is not active or invoked 
    and if you are trying to execute test class of script 
    the call that script in your test class using (class_name.Method).

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
rajubalajirajubalaji
Hi Ajay,

Please find below code and i tried so much but my code was not crossing morethan 10%.So can You please help me on this issue.

@isTest
Global class BulkPatientDeactivationResponseTest{
    
@isTest
    static void testHttpPost(){
        Test.startTest();
        Account acc1= new Account();
        acc1.Name ='Test';
        insert acc1;
        acc1.id      = acc1.id;
        acc1.name    = 'Test';
        String myJSON = JSON.serialize(acc1);
        RestRequest request = new RestRequest();
        RestResponse response = new RestResponse();
        request.requestUri ='/services/apexrest/BulkPatientDeactivationResponse';
        request.httpMethod = 'POST';
        RestContext.request = request;    
        RestContext.response = response;
        RestContext.request.requestBody = Blob.valueOf(myJSON);
        BulkPatientDeactivationResponse.doPost();
        test.stopTest();
    }
    
     static testMethod Void testBulkPatientDeactivationResponsesaveAttachment(){
        HubTestController.createCustomSettings();
        Test.startTest();   
            Hub_Patient__c pt = HubTestController.getMockPatientObject();
            Attachment att = new Attachment();
            String newBody = 'Test';
            att.Body = EncodingUtil.base64Decode(newBody);
            att.Name = 'Test';
            att.OwnerId = UserInfo.getUserId();
            att.parentId = pt.AccountID__c;
            insert att;
            String TransactionType = 'BulkDeactivateUser';
            String transactionId = BlueStarTransactionDetails.CreateInitialOutboundTransactionRequestForAccount(TransactionType, att.Id,pt.Enviornment_Code__c);
            BulkPatientDeactivationController.CreateBulkDeactivateUserTransaction(TransactionType, 'wd', att.Id, '', False,TransactionId);
             List<TransactionDetail__c> tranList = [select Id, Transaction_Status__c, Response_JSON__c, HUB_Practice__c, HUB_Provider__c, Comments__c, Request_JSON__c from TransactionDetail__c where FileID__c = :fileName and Name = :type Limit 1];
            RestRequest req = new RestRequest();
            RestResponse res = new RestResponse();
            req.httpMethod = 'POST';
            RestContext.request = req;
            RestContext.response = res;        
            String str = '{"Response":{"Header":{"TransactionType":"BulkDeactivateUser","TimeStamp":"10-10-2019 14:01:16:342","FileID":"BulkDeactivateUser.a0f4C000001mXCfQAM","Status":"Success"},"ResponseType":{"AccountCode":"TestAcc","SuccessUsers":"[{\"Email\":\"vhansda+326@welldocinc.com\",\"EmailHash\":\"a5u0cFn7xoeb9psTF9LAPcs/drHQwaplp+Jp7ElYpddfY9NVXyuTV5jwOFm3PuY0G7z8vOQNnt88v427iuIWtw==\",\"DeactivateUser\":\"Y\",\"BlueStarID\":\"W1000006125\",\"StatusID\":2,\"OldStatusID\":1,\"RowVersionID\":\"AAAAAADk7ho=\",\"PatientID\":264730,\"ErrorList\":null,\"Errors\":null}]"}}}';     
            RestContext.request.requestBody = Blob.valueOf(str);
            BulkPatientDeactivationResponse.doPost();
         Test.stopTest();
    }
    
    static testMethod void testTransactionResponseBulkUpdatePrescription(){
        HubTestController.createCustomSettings();
        Test.startTest();
        Account acc = getMockAccount();
        Hub_Patient__c pt = HubTestController.getMockPatientObject();
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();
        String responseBody  = '{"Response":{"Header":{"TransactionType":"BulkUpdatePrescription","TimeStamp":"12-16-2016 15:12:48:224","FileID":"BulkUpdatePrescription.a0fP0000002cYyMIAU","Status":"Success"},"ResponseType":{"BlueStarID":"W0000010726","FailedUsers":null}}}';
        String requestBody = '{"Request":{"Patient":{"Prescription":{"RxStartDate":"2017-01-15","RxNumber":"N/A","RxExpirationDate":"2017-01-20","RegisteredPharmacist":"N/A","RefillsLeft":12,"PayerType":"N/A","NumberOfFillWritten":12,"FillDate":"2017-01-15","DaysFilled":30,"BlueStarID":"W0000010726"}},"Header":{"TransactionType":"BulkUpdatePrescription","TimeStamp":"12-16-2016 20:41:18:578","FileID":"$FileID"}}}';
        req.requestBody = Blob.valueOf(requestBody);
        res.responseBody = Blob.valueOf(responseBody);
        req.requestURI = '/TransactionResponse/*';  
        req.httpMethod = 'Post';
        RestContext.request = req;
        RestContext.response = res;
        TransactionResponse.doPost();
        Test.stopTest();
    }
    
    static testMethod void testBulkPatientDeactivationResponse(){
        Test.startTest();
        HubTestController.createCustomSettings();
        MultiStaticResourceCalloutMock multimock = new MultiStaticResourceCalloutMock();
        Default_Settings__c settings = Default_Settings__c.getInstance('Configuration Values'); 
        multimock.setStaticResource(settings.Security_Token_URL__c, 'MockResponseGetToken');
        multimock.setStaticResource(settings.Base_URL__c + System.label.PatientEnrollment, 'MockResponseCreateEnrollment');
        multimock.setStatusCode(200);
        multimock.setHeader('Content-Type', 'application/json');
        Test.setMock(HttpCalloutMock.class, multimock);
        Hub_Patient__c pt = HubTestController.getMockPatientObject();
        //CreateEnrollment(String patientID, String HubCode, String GivenName, String FamilyName, Date DOB, String Gender, String Email, String PatientProviderId, String PatientPracticeId, String PatientPracticeAddressId, String Prefix, String Suffix, String GivenName2)
        CreatePatientEnrollment.CreateEnrollment(pt.Id,pt.SampleCode__c,pt.GivenName__c,pt.FamilyName__c,pt.DOB__c,pt.Gender__c,pt.Email__c,pt.Provider__c,pt.Practice__c,pt.Practice_Address__c,pt.Prefix__c, pt.Suffix__c,pt.GivenName2__c,'bst');
        CreatePatientEnrollment.getDateStringForMedicalHistory(System.today());
        Test.stopTest();
    }
    
    static Account getMockAccount(){
        
        Account pAcc  = new Account(); 
        pAcc.Name = 'WellDoc';
        pAcc.BluestarId__c = 'WD';
        pAcc.Access_Type__c = 'ImmediateAccess';
        pAcc.Payment_Type__c = 'PaidByInsurance';
        pAcc.Sample_Code_Required__c = true;
        pAcc.Enviornment_Code__c = 'bst';
           pAcc.Country__c = 'UnitedStates';
        pAcc.Language__c = 'English';
        
        insert pAcc;
        
        Account acc  = new Account();
        acc.ParentId = pAcc.id;
        acc.Name = 'Model4';
        acc.BluestarId__c = 'M';
        acc.Access_Type__c = 'ImmediateAccess';
        acc.Payment_Type__c = 'PaidByInsurance';
        acc.Sample_Code_Required__c = true;
        acc.Patient_Profile_Managed_By_Self__c = true;
        acc.Country__c = 'UnitedStates';
        acc.Language__c = 'English';
        acc.Enviornment_Code__c = 'bst';
        insert acc;
        return acc;
    }
    
    static Account getMockAccount_Model2(){
        Account pAcc  = new Account(); 
        pAcc.Name = 'WellDoc';
        pAcc.BluestarId__c = 'WD';
        pAcc.Access_Type__c = 'ImmediateAccess';
        pAcc.Payment_Type__c = 'PaidByEnterprise';
        pAcc.Sample_Code_Required__c = true;
        pAcc.Enviornment_Code__c = 'bst';
        pAcc.Country__c = 'UnitedStates';
        pAcc.Language__c = 'English';
        insert pAcc;
        
        Account acc  = new Account();
        acc.ParentId = pAcc.id;
        acc.Name = 'Model2';
        acc.BluestarId__c = 'M';
        acc.Access_Type__c = 'ImmediateAccess';
        acc.Payment_Type__c = 'PaidByEnterprise';
        acc.Sample_Code_Required__c = true;
        acc.Patient_Profile_Managed_By_Self__c = true;
        acc.Country__c = 'UnitedStates';
        acc.Language__c = 'English';
        acc.Enviornment_Code__c = 'bst';
        insert acc;
        return acc;
    }
}

Thanks Inadvance