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
Sami Ullah AzamSami Ullah Azam 

Write test case for Void Method without any parameters.

I have a method that returns nothing and take no parameters. It just take values from VF page and query the Object to retrieve results and set them to variables. How can I write test case for this functions.?
Please Help!!
Sami Ullah AzamSami Ullah Azam
public void updateValvePrice()
    {
    
    c.level__c = c.level__c .subString(0,3);
    
    c.level2__c = c.level2__c .subString(0,2);
    
            
   if( c.level__c == 'AMB' || c.level__c == 'AMC' )
    {
    
        string strQry = '';
        List<VWC_AllValvesDetailed__c> lstResults;
        try {            
                       
strQry = 'Select v.ListPrice_calc__c, BearingAndSealsPrice__c, BodyMaterialPrice__c, ShaftMaterialPrice__c, TrimMaterialPrice__c,' +
                             ' OrderCode__c, ANSIPressureClass__c, cv10__c, ANSIShutoffClass__c From VWC_AllValvesDetailed__c v where Series__c = \'' + c.level__c + '\'';
            
   if (c.My_Body_Material__c != '') {
 strQry += ' and BodyMaterial__c = \'' + c.My_Body_Material__c + '\'';
            }

            lstResults = Database.query(strQry);
            
   for (VWC_AllValvesDetailed__c option : lstResults){
                strValvePrice = String.valueOf(option.get('ListPrice_calc__c'));
 
               decValvePrice = decimal.valueOf(strValvePrice);
            }
        }
        catch (QueryException e) {
            ApexPages.addMessages(e);
        } 
     
}

 
Banwari kevat1Banwari kevat1
Hi Azam,
   can you share you whole code of class so that it will be easy to know about which variables are initializes when page loaded.?
Sami Ullah AzamSami Ullah Azam

These are picklists that directly coming from VF page. Some values I am triming here and some using directly. The wohle code of class is so much big. If it causing the problem to understand the method, I will share the whole code.Thanks

Amit Chaudhary 8Amit Chaudhary 8
Please try like below

CLASSNAME obj= new CLASSNAME();
obj.c.level__c ='AMC';
obj.updateValvePrice();

Let us know if this will help you
 
Sami Ullah AzamSami Ullah Azam

Hi Chaudhary,
       Thanks for the reply, I was busy with other tasks. I test it now but I am getting error of " System.NullPointerException: Attempt to de-reference a null object". The code is working fine when I use string instead of "c.level__c". c.level__c is a field of an object. Can you please tell me how can I test the method using the fields of an object. I initialize the c.level__c in constructor but didn't work.

your help shall be highly appreciated!
Thanks

Sami