3 Replies Latest reply on Jul 8, 2011 3:54 AM by ViolinistJohn

    Using FlexUnit to test Extensions

    ViolinistJohn

      Is it possible to use Flexunit to test code wrtten using extension builder?  If so how do you do it?

       

      In my extensions for Premiere Pro I've used the Mode View Presenter pattern so that the code is not all in the code behind the GUI or buried inthe mxml itself.  This was done in part to allow me to write unit tests for my presenter class(es) so I can remove the need to have the GUI up when testing and to help with long term maintainability.

       

      So I tried to get the test case created and the options are missing from the context menu. I assume this is for a good reason but I haven't seen any description of why.  No problem I have some components I use for extension configuration, data logging and error handling (which I already have tests for) so I pretended to create a test there and then redirected it to the extensions location.  A test case gets generated against my presenter so I thought I was up and running.

       

      Then I tried to run the tests so that they all fail and it appears it is trying to start the application so I get comlaints about needing a debug version of Flash player and then it seems to hang waiting for the host app (premiere) to start.  But the host app is not needed in this case as all I'm doing is testing the code in the client - and remote services but nothing that requires a GUI - that's the idea of using MVP anyway.

       

      So I end up with errors on all my tests rather than failures and I don't see a way to get this to work.

       

      Any ideas anyone?

       

      Thanks

       

      John

        • 1. Re: Using FlexUnit to test Extensions
          david_a_clark Adobe Employee

          Have to admit I'm not too experienced with using FlexUnit for CS Extension projects, but I know it can be done.

           

          If the problem is obvious to someone else maybe they can chime in. In the meantime can you give some more details:

           

          • It sounds like your tests are actually running, but failing, is that right? What are the errors? Have you tried debugging while the tests are running?
          • Which FlexUnit version are you using?
          • How are you launching the tests?
          • 2. Re: Using FlexUnit to test Extensions
            ViolinistJohn Level 1

            David,

             

            My tests are not failing they are erroring.  I have just tried debugging and I never get into the tests or the code that is being tested.  I believe this is because the extension is waiting for Premiere (the extension host) to start and it never gets started.

             

            I'm using Flexunit 4 and the Hamcrest extensions.

             

            I'm running the tests from within the Flash Builder GUI using the run button in the Flex Unit Results page.  This gives me a dialog to choose which tests to run and I have cut it down to a single test for now.  Then I get the message about needing a debug Flash Player - click OK on that and all the tests error and the Launching FlexUnit Application dialog sits there waiting to connect to the running application.  The only way out is to Cancel that now.  So it appears the flexunit tests are not connecting to a running application but no hint as to what that app might be.

             

            I think I understand why it needs the Flash Player - that's the window it reports the flexunit run in - black with white text saying 1 test, 1 error etc and telling me I can now close it.  So the tests have finished. 

             

            I think I'm missing something obvious but not sure what.

             

            Thanks

             

            John

            • 3. Re: Using FlexUnit to test Extensions
              ViolinistJohn Level 1

              I think I have worked out a way to do this after much trial and error.

               

              1.  Create a new Flex Project in the same workspace as the extension.  Called something like ExtensionTests

              2.  In the test project properties set use the Build Path to include the source from the extension.  Probably have to be careful not to change this code from inside the test project.

              3.  Add any service references to the test project. I have 2 web services I use and these have to be referenced in the test project else I get compilation errors.  I also called them the same names and modified the constructors in the same way I did for the extension.

              4.  Create a test case as normal for a class in the source reference.

              5.  Run the tests.  They all fail as expected.

              6.  Modify a single test to actually do something to cause it not to fail.

              7.  Re-run tests.  Get the expected result of 1 success and N failures.

               

              Whilst not ideal because I have a reference to the real source in my test project I can at least test this source now.

               

              Hope this helps anyone else who reads this.

               

              John