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
AdaptiDevAdaptiDev 

how to test/deploy a custom component and his controller

I have created a custom component with a controller.

 

When you put this custom controller on a page, you have to set 2 parameters (objectname & searchtext).

The controller will get the values out of this custom controller by doing:

 

String strObjectName = System.currentPageReference().getParameters().get('objectname');

String strText = '%'+System.currentPageReference().getParameters().get('searchtext')+'%';

 
 
Everything is working but now I need to create a test class to deploy this component and controller.
 
How can I create a Test class that will pass the 2 parameters to the controller or how can I make the controller get a result out of System.currentPageReference().getParameters().get('objectname'); ?
 
Thanks for the info? 
Best Answer chosen by Admin (Salesforce Developers) 
AdaptiDevAdaptiDev

I have found a solution, but I m not sure if this is the best one.  So please comment on this:

 

I have created a test visualforce page (test_autocomplete) with a controller AutoComplete_Controller.  This is the controller of the Custom Comonent.

 

<apex:page controller="AutoComplete_Controller">

    TEST PAGE FOR AUTOCOMPLETE

</apex:page>

 

 

Then I have create a Test Class where I pass the 2 parameters:

 

        AutoComplete_Controller myACController = new AutoComplete_Controller();

        PageReference myPage = new Pagereference('/apex/test_autocomplete?');
        myPage.getParameters().put('objectname','Account');
        myPage.getParameters().put('aname','test001');
        Test.setCurrentPage(myPage);       
 

 

Then I start calling all methods that are available in the controller.

 

 

I m not sure I need to test the Custom Component, since I able to recreate this one in the Live Environment.

 

All Answers

AdaptiDevAdaptiDev

I have found a solution, but I m not sure if this is the best one.  So please comment on this:

 

I have created a test visualforce page (test_autocomplete) with a controller AutoComplete_Controller.  This is the controller of the Custom Comonent.

 

<apex:page controller="AutoComplete_Controller">

    TEST PAGE FOR AUTOCOMPLETE

</apex:page>

 

 

Then I have create a Test Class where I pass the 2 parameters:

 

        AutoComplete_Controller myACController = new AutoComplete_Controller();

        PageReference myPage = new Pagereference('/apex/test_autocomplete?');
        myPage.getParameters().put('objectname','Account');
        myPage.getParameters().put('aname','test001');
        Test.setCurrentPage(myPage);       
 

 

Then I start calling all methods that are available in the controller.

 

 

I m not sure I need to test the Custom Component, since I able to recreate this one in the Live Environment.

 

This was selected as the best answer
elpaso750elpaso750

Hi, 

how are you.

 

I'm  in the same situation as you were, I created a custom component and relative controller to be used in email Templates in order to sort OpportunityLineItems.

 

The component and Controller just work great.  But when it comes to creating the TEST class, I'm just keep banging my head on different walls.

 

Any chance yuo could post your example

 

thanks

Alex