2 Replies Latest reply on May 3, 2010 7:48 PM by deshartman

    Unit testing Main Application with URL fragment




      I have written an application that performs login, register and reset password. As part of this, the user receives an e-mail with a URL containing fragments to direct them to the correct start screen on the application. An example:


      http://localhost:8080/Server/Client-debug/Client.html#reason=register&email=des@someplace. com&code=8846748080/Server/Client-debug/Client.html#reason=register&email=des@someplace.com&code=884674


      I have written the code to deal with the URL in the main Client.mxml file and all of this works. the Client.mxml dispatches a particular Event depending on the content of the URL, but I would like to retrofit FlexUnit4 testing for this. I have no idea how to set this up so that my tests will take a URL and I assert that a particular event has been dispatch.


      Could you please help me out with setting this up to test? There will be three different URLS used to test


      http://localhost:8080/Server/Client-debug/Client.html#reason=reset&email=des@someplace.com &code=8846748080/Server/Client-debug/Client.html#reason=reset&email=des@someplace.com&code=884674


      http://localhost:8080/Server/Client-debug/Client.html#reason=register&email=des@someplace. com&code=8846748080/Server/Client-debug/Client.html#reason=register&email=des@someplace.com&code=884674






        • 1. Re: Unit testing Main Application with URL fragment
          legrosb Level 3

          @des - Couple suggestions.  You can add your application as node on the stage via the UIImpersonator (a sort of subapplication) and see if the event is dispatched by the application.  Another approach which would probably be cleaner, is to separate the concerns of routing from the main application class.  If this is the same app you were working on when we conversated over on the Swiz mailing list, then a NavigationController may be a good fit for your architecture.  If not a controller, then some type of NavigationHelper to delegate the responsibility of examining URLs and dispatching events to keep the concern out of you main application and make testing simpler.  Just some suggestions, to read more about the UIImpersonator, check out http://docs.flexunit.org/index.php?title=Writing_an_Async_setup#Create_a_New_Test_Case for some ideas.


          Let us know how it goes.



          • 2. Re: Unit testing Main Application with URL fragment
            deshartman Level 1



            Took your suggestion and move the URL code out of the main class to one of the presenters. I did not realise I could still get the URL at that level. Anyway, it works and I can unit test the URL parsing now.