9 Replies Latest reply on Jun 23, 2010 6:18 PM by legrosb

    can i reference external flex-config in flexunit ant task?

    snowymike

      flexunit gurus,

       

      i'm trying to figure out how to best specify the compiler arguments for the flexunit ant task in flexunit 4.1 beta 1.  from the documentation i see this sample flexunit usage:

       

      <flexunit workingDir="${bin.loc}" toDir="${report.loc}"
      haltonfailure="false" verbose="true" localTrusted="true">
      <testSource dir="${main.src.loc}" />
      <testSource dir="${test.src.loc}">
      <include name="**/*Test.as" />
      </testSource>
      <library dir="${lib.loc}" />
      </flexunit>

       

      in this example, the source and library paths are explicitly listed.  in this simple example all the needed libraries reside within a single directory.

       

      when i build my application, i use a custom flex-config.xml file, as the following snippet shows:

       

              <mxmlc file="${application.file}" output="${swf.debug.file}" debug="true" headless-server="${headless.server}">
                  <load-config filename="${flex.config.file}" />
              </mxmlc>

       

      in that custom flex-config.xml file i list all the build options (e.g. source dirs, library paths, theme, etc.) appropriate for building the application.  the libraries i reference are in a number of different directories (in general each 3rd party library is in a different directory).

       

      in the flexunit task, i could individually reference all the same libraries that are in the flex-config.xml, but that'd be a pain to keep them in sync.  i suppose i also could parse the flex-config.xml to extract the library information and use that to populate the library argument.  really what i want to say in the flexunit task is "build all source and tests as indicated in flex-config.xml, then run the tests", perhaps with a syntax like the following:

       

       

       

      <flexunit workingDir="${bin.loc}"  toDir="${report.loc}"
      haltonfailure="false" verbose="true" localTrusted="true">

                  <load-config filename="${flex.config.file}" />
      <testSource dir="${test.src.loc}">
      <include name="**/*Test.as" />
      </testSource>

      <library dir="${flexunit.lib}" />
      </flexunit>

       

      i'd rather keep the flex-config.xml file free of any test specific information, so ideally i'd specify the path to the flexunit swc's and the test path in the flexunit task (as in the above example).

       

      is there support for such usage currently or planned for in the future?  recommendations on how best to accomplish my goal of not duplicating library information already present in a custom flex-config.xml?

       

      thanks.

       

      -mike

        • 1. Re: can i reference external flex-config in flexunit ant task?
          legrosb Level 3

          @mike - The implementation for 4.1 was left relatively simple for a first round since the alternative always exists to compile your test SWF (as had to be done prior to 4.1.0).  I wanted to explicitly avoid recreating the work of the Flex SDK Ant tasks since it'd be tedious to keep the FlexUnit task in sync with the SDK tasks.  If the only issues you're running into are library related, <library> is an Ant fileset with the **/*.swc filter applied.  For whatever directory you specify, it will find every SWC in every sub-folder automatically for you.  To write out what the implicit fileset looks like:

           

          <library dir="[some directory]">

             <include name="**/*.swc" />

          </library>

           

          If you have SWC's stored in assorted folders, try specifying the ${basedir} for in library fileset and see if that is sufficient.  If you're using a custom flex-config however, I have a feeling this will not be enough.

           

          As far as the flex-config goes, I'd suggest filing a feature request and getting others to vote on it.  If users are finding the configuration for test compilation is too simple, maybe we can get a feel for what config options would help the majority of folks and add it in 4.2.  Since you always have the option to compile your own test SWF, I think seeing some use cases first would be helpful for us.  That being said, your request doesn't seem unreasonable, so I'll vote for the feature request for sure.

           

          I need to update the wiki with some more notes regarding limitations of compilation using the Ant task.  If you haven't seen it already, I've been updating the wiki for the Ant task regularly at http://docs.flexunit.org/index.php?title=Ant_Task with the fruits of our discussions.  Hope this helps.

           

          -Brian

          • 2. Re: can i reference external flex-config in flexunit ant task?
            snowymike Level 1

            hi brian,

             

            thanks for your response.

             

            i understand the desire to avoid re-implementing the flex sdk ant tasks.  i'm not sure that can reasonably be accomplished wihen the TestRunner is dynamically generated from within the flexunit task.  in addition to the source path and library path, the theme setting and namespaces settings can affect successful compilation, and the runtime-shared-library-path setting can affect whether the produced swf runs correctly.

             

            perhaps there's an alternative.  what if we separate the creation of the TestRunner.mxml from the compilation and the execution of the tests.  if flexunit offers an ant task that can produce (but not run) a TestRunner.mxml, i can write the mxmlc task that compiles it properly, and then i can invoke the old style flexunit specifying the swf argument.  this would still accomplish my primary goal of not needing to manually enumerate every test file in a TestRunner.mxml that i have to maintain (and which neither Flash Builder nor maven builds require).  to compile the TestRunner.mxml, i'd load in my custom flex-config.xml, then append to the source path and library path to include my test directory and flexunit libraries.

             

            maybe something like the following to create the TestRunner:

             

            <generatetestrunner output="${bin.loc}/TestRunner.mxml">

                      <testSource dir="${test.dir}">
                         <include name="**/*Test.as" />
                      </testSource>

            </generatetestrunner>

             

            thoughts?

             

            one other thing i noticed about the current library argument to flexunit is that it assumes a directory even if you provide an explicit path to an swc (i tried switching <library dir...> to <library file...> but that didn't seem to make a difference).  in my case, there are specific swc's i need in the library path, and the task assuming i mean a directory when i specify an explicit swc is problematic.  the directory my swc libraries are contained in sometimes contain multiple and conflicting versions of a library (each library directory contains various snapshot builds of the library).  i need a way to explicitly indicate which library to use.

             

            finally, could you point me to the java source for the flexunit ant tasks?  i've found the flexunit action script source ok but haven't found where the java ant task is defined.

             

            thanks.

             

            -mike

            • 3. Re: can i reference external flex-config in flexunit ant task?
              legrosb Level 3

              @mike - While I'm familiar with the options available when compiling a SWF, initially our goal is to support the simplest use case for compiling a test runner, which entails using the defaults setup by the flex-config in the SDK.  Although it may not satisfy your use case, compiling with custom namespaces, themes, and rsls is the not the initial use case for the Ant taks compilation feature.  Yes, unfortunately, you won't be able to take advantage of the test scanning feature in 4.1, but I don't think it's unreasonable to satisfy your request of specifying a custom flex-config in the FlexUnit Ant task for 4.2.  Since we're in beta for 4.1 we have a feature lock down and I'm unable add support for a custom flex-config file to the Ant task at this time.  That being said,  I will talk to the team and see what they think about adding this feature for beta2 since it shouldn't be difficult, just a break with procedure.

               

              In terms of fragmenting the Ant task, you're welcome to post a feature request in JIRA and have others vote on it.  I personally would like to keep things simpler and in a single Ant task, but at the end of the day, we want to do what's easiest for the community, so we definitely aren't closed off to new ideas.

               

              In terms of the library task not working with file, this is bug and I will look into it this weekend.  I can't guarantee a timeframe for the fix as of yet, but it'll be in for 4.1 final.  Did you try specifying a top-level directory and letting the filterset grab the SWC's in that file tree?

               

              In terms of the Java source code for the Ant task, you can find it on GitHub in the FlexUnit4AntTasks project @ http://github.com/flexunit/flexunit/tree/master/FlexUnit4AntTasks/.

               

              Thanks for digging into the nitty-gritty with us.  We're definitely listening to your feedback and want to get something working for ya, I'm just not sure of the time tables yet.

               

              -Brian

              1 person found this helpful
              • 4. Re: can i reference external flex-config in flexunit ant task?
                snowymike Level 1

                thanks for the source path.

                 

                the library argument seems to work fine when i just specify a directory - i do that to pull in all the flexunit swc's.  it's when i specify a file explicitly that it pulls in more than it should.

                 

                makes sense to start with simple compilation options for 4.1; i'll look forward to 4.2 enhancements.  like you i'd also prefer if the flexunit task took care of all the compilation issues inline rather than using a separate task - i offered generatetestrunner as an alternative that would avoid needing to re-implement all of the sdk ant task support.  long term i think there will need to be a way for sophisticated compilation options for the flexunit task.  i don't do much sophisticated in terms of customizing flex-config.xml - in addition to setting/updating source-path and library-path, i set the theme to halo and turn off RSLs.  right now i can't do the last 2 with the flexunit task without updating the SDK's flex-config.xml.  given the types of unit testing i'm planning to add initially i'm guessing i can live without the theme/RSL settings for now, and i'll just set the source and libraries in the ant build.xml file once <library file...> is fixed.  then when flex-config.xml support is added to the flexunit task i'll remove that duplication and have the compilation occur just as it would for the production source (with the addition of including the test source and flexunit swc's).

                 

                i don't need generatetestrunner if the flexunit compilation options will be enhanced in the 4.2 timeframe.  do you want me to open the jira ticket on flex-config.xml support and otherwise enhancing the compilation options for the flexunit task, or will you submit/track that?  either way works, let me know your preference.

                 

                thanks.

                 

                -mike

                • 5. Re: can i reference external flex-config in flexunit ant task?
                  legrosb Level 3

                  @mike - Ok, just spoke with Labriola and he's had to solve a similar scenario for a project he's working on.  He had a great suggestion of just creating a copy of the SDK, changing the flex-config.xml in that SDK, and pointing your FLEX_HOME property to that altered SDK until 4.1 final is released.  Once 4.1 is released, the first feature we'll put in the Ant task for 4.2 is support for a flex-config.xml file.  With the 4.1 release looming, we've got to stick to our commitment of feature lock down for now.  If you'd like to open the feature request for supporting a custom flex-config for 4.2, it'll be the first thing on my list.  Based on how motivated I'm feeling this weekend, I may even just put it in a branch on my fork.  If you want to file a bug for that library file issue as well, that'd be cool.

                   

                  Thanks for back and forth; I'm hoping we can get you what you need since yours has the potential to be a common use case for the Ant task.

                   

                  -Brian

                  1 person found this helpful
                  • 6. Re: can i reference external flex-config in flexunit ant task?
                    snowymike Level 1

                    Submitted FXU-115 and FXU-116.

                    • 7. Re: can i reference external flex-config in flexunit ant task?
                      JonnyReeves Level 1

                      Just to chime in on this thread:

                       

                      The project I work on is split across several (~40) modules and is faced with the exact same problem.  We have externalised most of our "per-module" compiler configuration into mxmlc-config.xml files; however we have also created our own macro definition that wrap the mxmlc jar adding in compiler constants which are relevant to all of our projects.

                       

                      I personally would love to have the ability to fully break the flexunit ANT tasks down into three distinct steps:

                      • Generation of the TestRunner.mxml file which pulls in a generated TestSuites.as file
                      • Compilation of the TestRunner into a SWF
                      • Execution of the TestRunner in the flash player and the resulting report generation.

                       

                      This would then grant us precise control over how the TestRunner is compiled into a SWF without the hassle / complication of generating the TestRunner.

                       

                      I've opened a request on the JIRA for this feature: https://bugs.adobe.com/jira/browse/FXU-118

                      • 8. Re: can i reference external flex-config in flexunit ant task?
                        legrosb Level 3

                        @JonnyReeves - Thanks for the feedback and filing the feature request.  I'm not against something like this and +2 from the thread is a good showing that it warrants some attention.  The interface and usage for the task, or multiple tasks, will definitely need to be hashed out.  I'll make some notes on the issue and let's try to get people to vote on it.  We've got a full roster for 4.2 already in terms of tooling (heartbeat messaging, code coverage, Apache Ivy integration, plus more) but based on the amount of feedback we can get from the community, maybe we can get something slated.

                         

                        Thanks again for the feedback.

                         

                        -Brian

                        • 9. Re: can i reference external flex-config in flexunit ant task?
                          legrosb Level 3

                          Oh and just a note, I've added the <flexConfig> element to my 4.2 branch on my github fork for the Ant task for the brave ones out there.  This syntax will call mxmlc with the -load-config argument with a space (not a +=) and the provided value.  This element is just the Property task in disguise for now, so all property of Property are available. 

                           

                          This branch is going to get pretty unstable in a few weeks, so be forewarned. 

                           

                          -Brian