+ Start a Discussion
sfg1sfg1 

code coverage for constructor with parameters(controller)

Need help in code coverage for constructor with parameters(controller).
PScRMAExtension is EXTENSION
PScRMAExtension_v1  is CONTROLLER

/*
    *Class constructor
    */
    public PScRMAExtension(PScRMAExtension_v1 objext)
    {
        system.debug('$$$ <PScRMAExtension::PScRMAExtension>');
        parent_case_id = ApexPages.currentPage().getParameters().get('id');
        //parent_case_id = '50011000008KcEV';
        //currentInstance = this;
        //case_list = (Case)controller.getRecord();
        RMALineItemCnt = 0;
        show_RMA_list = FALSE;
        showAdvanceExchange = FALSE;
        show_flash_alert = FALSE;
        show_expired_contract_alert = FALSE;
        accept_expired_contact = FALSE;
        show_case_detail = FALSE;
        show_fru_detail = FALSE;
        asset_exists = FALSE;
        show_cli_grid = FALSE;
        show_asset_grid = TRUE;
        disable_save_btn = FALSE;
        show_add_line_item = FALSE;
        show_expired_Asset_alert =FALSE;
        isRMASLASameDay = false;
        isshowassetExipre=FALSE;
        isshowRMAexits =FALSE;
       
        //show_replacement_part_confirmation = FALSE;
        //accept_replacement_part = FALSE;

        RMA_line_item_wrapper_list = new List<PScRMALineItemsWrapper>();
        new_line_item_obj = new RMA_Line_Items__c();
        RMA_line_item_list = new List<RMA_Line_Items__c>();
        view_line_item_obj = new RMA_Line_Items__c();
        line_save_text = 'Add Line Item';
        obj_line_item_tosave = new List<RMA_Line_Items__c>();

        rmaAssignedRtName = '';
        primaryOwnerFld = '';
        secondaryOwnerFld = '';
        default_country = 'United States';

        //replacement_part_error_msg = '';
        system.debug('show_add_line_item1' + show_add_line_item);

        //stateList = new List<selectOption>();
        //stateList.add(new selectOption('', '--None--'));

        //system.debug('$$$ parent_case_id: ' + parent_case_id);
        if(parent_case_list == null)
        {
            parent_case_list = [ SELECT Account.Name, Account.Company_Name__c, Account.ShippingStreet, Account.ShippingCity, Account.ShippingState, Account.ShippingCountry, Account.ShippingPostalCode, Account.Phone, Account.Email__c, Contact.Name, Contact.MailingStreet, Contact.MailingCity, Contact.MailingState, Contact.MailingCountry, Contact.MailingPostalCode, Contact.Phone, Contact.Email, AccountId, ContactId, AssetId, CaseNumber, Subject, Description, Status, Priority, Severity__c, Serial_No__c, Platform__c, Product_Series__c, Ship_To_Account__c FROM Case WHERE Id = :parent_case_id ];
            account_id = parent_case_list.AccountId;
            asset_serial_no = parent_case_list.Serial_No__c;

            if(parent_case_list.Account.Company_Name__c != null)
            {
                account_name = parent_case_list.Account.Company_Name__c;
            }
            else
            {
                account_name = parent_case_list.Account.Name;
            }

            populateIB();
        }
        system.debug('$$$ parent_case_list: ' + parent_case_list);

        List<CreateCaseRT__c> ccRtList = CreateCaseRT__c.getAll().values();
        if(ccRtList.size() > 0)
        {
            for(CreateCaseRT__c t : ccRtList)
            {
                if(t.Case_Trans_Type__c == system.label.RMA_Transaction_Type)
                {
                    rmaAssignedRtName = t.Name;
                }
            }
        }

        getFlashAlerts();
        RMALineItemDetails();
        getReplacementPart();
        getRMALineItemCnt();
        
        system.debug('in PScRMAExtension show_cli_grid ' + show_cli_grid);
        system.debug('in PScRMAExtension show_asset_grid ' + show_asset_grid);
    }
Kapil KaushikKapil Kaushik
Hi Dhana1,

You can cover your code like this :

PScRMAExtension_v1  extension = new PScRMAExtension_v1();
PScRMAExtension myController = new PScRMAExtension(extension);

and further you can continue with your myController variable to cover methods code.

Please post if you have any query.
RKGRKG
@isTest
public class PScRMAExtensionTest
{
    static testmethod void PScRMAExtensionTestCase()
    {
// wirte code for insert case and then pass case id in parameter  
          PageReference testPage = Page.oMarketoArticle;
          testPage.getParameters().put('id', '12345'); // pass your case id insteaded of 12345
          Test.setCurrentPage(testPage);
          PScRMAExtension obj=  PScRMAExtension(new PScRMAExtension_v1());
     } 
}
Nagendra Prasad ChNagendra Prasad Ch
//Insert test Case record
// insert Case;    

Test.startTest(); 

Test.setCurrentPage(Page.Your VF page);  // Give your VF page name here 
ApexPages.currentPage().getParameters().put('id',Case.Id);// Give your inserted test case Id     
ApexPages.StandardController sc = new ApexPages.standardController(Case);
PScRMAExtension psExt = new PScRMAExtension(sc);  

//call any uncovered methods directly from here if needed, 
//Example: psExt.Methode();

Test.stopTest();