2 Replies Latest reply on Mar 3, 2010 1:03 PM by injpix

    Delegate class to access non-public methods during testing?

    injpix Level 3

      In the following video, towards the end, someone asked that FlexUnit assumes functions and methods are to be public when tested.

       

      http://tv.adobe.com/watch/max-2008-develop/testing-your-flex-applications-by-michael-labri ola/

       

      The speaker replied (@ 52:25),  to use Delegate classes, which are linked in when being tested. 

       

      Can someone show me an example of this?  Thanks.

        • 1. Re: Delegate class to access non-public methods during testing?
          mlabriola Level 4

          Delegate classes will allow you access to some internals of the Adobe Flex component framework. They do so by capturing events and allowing you to replay them. If this is the specific scenario you need to test, then delegate classes can work for you.

           

          However, in general, we don't test private methods. In ActionScript there is no way for an external class to gain access to the private members of another, so these get tested only by their individual calls from public members.

           

          Mike

          • 2. Re: Delegate class to access non-public methods during testing?
            injpix Level 3

            Mike, thanks for the reply!

             

            As I am new to unit testing, things are still solidifying.  I do understand that Unit Testing, “tests the smallest functional unit of code”, which are methods and functions.  However, I incorrectly assumed that *every* method needed to be tested *directly*.   Hence, I thought all methods would have to be public.  So that would have blown encapsulation out of the water.  Now I understand from your reply, that private methods get tested indirectly from public methods.  And that seems more ideal.

             

            Thanks again.