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
ayvakayvak 

pls help me in fixing the bug in testclass

How to cover below lines in testclass???

 List<Fee_Table__c> feeList = database.query(feeQueryStr);
if(feeList.size()>0)
                {
                    //RY:
                    for(Fee_Table__c fee: feeList)
                    {
                       feeRecordTypeMap.put(fee.RecordTypeId, fee);
                    } 
                    system.debug('### feerecordtypemap is created ###');                    
                    return feeRecordTypeMap;  
                 }
 Set<Id> prodIds = new Set<Id>();
                for (Product2 svc : lstProd)
                {                       
                    prodIds.add(svc.Id); 
                }
 Map<Id, Id> prodPEMap = new Map<Id, Id>();
                if(prodIds.size() > 0)
                {
                 
                    List<PriceBookEntry> peList = [select Id, Product2Id from PriceBookEntry where Product2Id IN: prodIds];
                    for(PriceBookEntry pe: peList)
                    {
                        prodPEMap.put(pe.Product2Id, pe.Id);
                    }
                }
                Map<String, Id> rtMapFee = rtMap('Fee_Table__c');

thank you
Best Answer chosen by ayvak
BALAJI CHBALAJI CH
You can use TestVisible annotation to allow test methods to access private or protected members of another class outside the test class.

Class with Private members:
public class TestVisibleExample {
    // Private member variable
    @TestVisible private static Integer recordNumber = 1;

    // Private method
    @TestVisible private static void updateRecord(String name) {
        // Do something
    }
}

Test Class for unit testing private members/methods:
@isTest
private class TestVisibleExampleTest {
    @isTest static void test1() {
        // Access private variable annotated with TestVisible
        Integer i = TestVisibleExample.recordNumber;
        System.assertEquals(1, i);

        // Access private method annotated with TestVisible
        TestVisibleExample.updateRecord('RecordName');
        // Perform some verification
    }
}

Please find below link for more information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm

Let us know if that helps you.

Best Regards,
BALAJI

All Answers

BALAJI CHBALAJI CH
Hi Ayvak,

You have to create test data for the Object "Fee_Table__c" in your Test class such that when you query with the string "feeQueryStr", records should be retrieved from the inserted test data.

 Let us know if you need more help.

Best Regards,
BALAJI
 
ayvakayvak
Thank you for ur time Balaji... this issue got fixed...
I have new query... how to add this private method in test class? can u show some example

  private Map<String, Id> rtMap(String obj)
    {       
            Map<String, Id> rtMap = new Map<String, Id>();
            List<RecordType> rtList = new List<RecordType>([select id, name from recordtype where sobjecttype=: obj]);
            for(RecordType rt : rtList)
            {
                rtMap.put(rt.name, rt.id);
            }
            System.debug('rtMap method' +rtMap);
            return rtMap;
           
    }
 
BALAJI CHBALAJI CH
You can use TestVisible annotation to allow test methods to access private or protected members of another class outside the test class.

Class with Private members:
public class TestVisibleExample {
    // Private member variable
    @TestVisible private static Integer recordNumber = 1;

    // Private method
    @TestVisible private static void updateRecord(String name) {
        // Do something
    }
}

Test Class for unit testing private members/methods:
@isTest
private class TestVisibleExampleTest {
    @isTest static void test1() {
        // Access private variable annotated with TestVisible
        Integer i = TestVisibleExample.recordNumber;
        System.assertEquals(1, i);

        // Access private method annotated with TestVisible
        TestVisibleExample.updateRecord('RecordName');
        // Perform some verification
    }
}

Please find below link for more information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm

Let us know if that helps you.

Best Regards,
BALAJI
This was selected as the best answer
ayvakayvak
thank you Balaji