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
boihueboihue 

Issue of Test Mothod module

Hi experts,

I have completed a new Visualforce Page and its controller and I am planning to deploy these changes to the production but I have encountered an issue in my Test Method module. I hope to get some helps from you.

 

Here are some lines of codes from my Controller:

 

public class OpportuniteProduitController {

       private final ApexPages.StandardController controller;

    

     public Boolean bValue {

        get {

                 return bValue;

        }

          set;

    }

 

     public String ProductName {

        get {

                 return sProdName;

        }

          set;

    }

      public String getTextStyle()

    {

          return 'color:blue; font-weight:bold; font-size:small';

    }

    ........

}

Here are the codes from my Test Method module:

 

 

public class OpportuniteProduitTest

{

    public static testMethod void OpportuniteProduitTest()

   {

        PageReference pageRef = new PageReference('Page.OpportuniteProduitPage');

        Test.setCurrentPage(pageRef);

 

       

        OpportuniteProduitController controller = new OpportuniteProduitController( null );

 

       

        controller.bValue();

        controller.ProductName();

        controller.getTextStyle();

 

        controller.Save();

        controller.Cancel();

    }

}

 

I always got the errors from the two following lines when I wanted to save the codes in IDE. What is the correct syntax should I use in this case?

        controller.bValue();

        controller.ProductName();

 

Best regards!

 

 

Message Edited by boihue on 01-30-2009 08:09 AM
jwetzlerjwetzler

You should be referring to your properties like controller.bValue, and you need to invoke them in ways that will call the getters and setters for your properties.  (controller.bValue = true will invoke the setter, for example).

 

However you need to be doing actual testing in your controller.  As it stands you're just calling all of the methods you have without verifying anything you get back.

 

If you're going to call getTextValue() you should verify it gives you back the right thing.  If you're going to call controller.save() or controller.cancel() check the PageReference you get back and make sure it's returning what you expect.

 

TestMethods are there for you to actually test the functionality of your controller and verify that the values that are returned to you are correct.  You should not be satisfied with a test method that only calls the methods but does nothing to check their accuracy. 

boihueboihue

Hi jwetzler,

 

Thanks for your quick response! I have just changed both lines to

controller.bValue = true;

controller.ProductName = 'Spot commercial';

 

And it works...

 

Best regards!

jwetzlerjwetzler
Good.  Again I would stress the importance of actually verifying the values you are calling in your testMethods, though...
boihueboihue

Hi jwetzler,

 

I would like to ask one more question, if there's a function like this, how should I put the test code in my Test Method module?

 

public List<OpportunityLineItem> results {

   get{

      results = [select PricebookEntry.Name, Section__c, Station__c, Type_creatif__c, Format_pub_web__c, ServiceDate,

                    Fin__c, Objectif_de_livraison__c, type_de_tarification__c, Taux__c, Valeur__c, UnitPrice

                         from OpportunityLineItem where OpportunityId = :sOppId order by PricebookEntry.Name];

        return results;

   }

    set;

}

 

Best regards!

Message Edited by boihue on 01-30-2009 11:47 AM