Skip navigation
Currently Being Moderated

Testing Application Components

Aug 30, 2011 5:56 AM

I'm not sure if you are aware, but it is currently very difficult to test spark Application components using FlexUnit and the UIImpersonator. An application component can't simply be added to UIImpersonator with addChild; there is already an existing Application for the test environment. What you have to do instead is create and add a SWFLoader and then use that to load an instance of the Application to test. The workaround is not very difficult, but having a mention of this issue in the documentation somewhere would have been helpful. Better yet perhaps add a function to UIImpersonator that takes care of the extra steps involved in testing an Application. What do you think?

 
Replies
  • Currently Being Moderated
    Aug 30, 2011 8:44 AM   in reply to bucpatr1

    Which version of FlexUnit are you using?

     

    As of 4.1 we allowed the interface to have an addElement() which accepts spark components just like the Spark Application?

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2011 11:24 AM   in reply to bucpatr1

    Its a little convoluted in Flash Builder 4, so what I would suggest first instead is that you just add the FlexUnit 4.1 swc to your library path of your test project. It should trump the existing version and let you test with 4.1 before you have to hunt down the existing swc, etc.

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2011 1:16 PM   in reply to bucpatr1

    Its okay that it is based on flex 3 components, it would just need to be compiled with the Flex 4 SDK or you need to wait until the next release of FlexUnit to make it cleaner.

     

    In the 4.1 release we basically look for global clues as to whether it is 4.x or 3.x as it is unfortunately difficult (as you have seen) to handle them both together.

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2011 1:17 PM   in reply to Michael Labriola

    I will see if we can accelerate any of this in a dot release.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2011 1:41 PM   in reply to bucpatr1

    Yes, it is completely usable.

     

    How it works is that FlexUnit tries to see if there is a mx.core.Container linked into your project. If there is, it uses that as the basis for the UIImpersonator. If there isn't one, then it uses spark.components.Group.

     

    It does this because it is possible to compile in Flex 4.x with or without the MX components.

     

    If your project has both, MX and Spark, then you can continue to use addChild() and you should be able to add either spark or mx components to the display list with 4.1.  If your project is spark only then you need to use addElement(). We are just trying to make this cleaner for future releases but it does work now.

     

    As far as the loader, etc. I certainly understand why you are doing that and if it works then by all means its a good solution. FlexUnit was never intended though to be able to test full applications, so things like applicationComplete were never on our radar. So, for now, you will need to continue your work around to have that functionality or, you could always manually dispatch it (myApp.dispatchEvent( new Event("applicationComplete") ) ) at the appropriate time.

     

    HTH,

    Mike

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)