8 Replies Latest reply on Apr 15, 2010 9:31 AM by gmaurice

    Setting compiler options when running unit tests

    gmaurice

      Hi,

       

      When I'm running unit tests from flash builder, is there a way to define compiler options? For example, I would like the compiler to ignore warnings and possibly set strict typing off.

       

      Thanks,

      Gilles

        • 1. Re: Setting compiler options when running unit tests
          gmaurice Level 1

          Let me describe the problem some more... if this isn't the right forum, please let me know which would be the appropriate forum for this...

           

          I have a flex library that has unit tests. When right-cliking on a test class, and clicking "Execute Flex Unit Tests", Flash Builder automatically creates "FlexUnitApplication.mxml" which is the application that runs the flex unit tests.

           

          I need to pass compile time options when FlexUnitApplication.mxml is built. For example, one option I need is "-include-libraries" which includes all the classes in the specified library even if the classes are not explictily referenced; these classes will be referenced dynamicaly at runtime.

           

          Does anyone know how to set these compile time options? I can do it in an ant task but it's so convenient to run a test case within flash builder that I wouldn't want to lose that capability.

           

          Thanks,

          Gilles

          • 2. Re: Setting compiler options when running unit tests
            mlabriola Level 4

            Gilles:

             

            If these can be linked against both the FlexUnit app and your own, then just right click on the project, got to properties, Flex Compiler and there is an Additional compiler arguments

             

            If not, it is possible to keep a separate project where the FlexUnit launcher lives and simply reference the source of your original project. That would let you separate the compielr arguments (at least in theory)

             

            Mike

            • 3. Re: Setting compiler options when running unit tests
              R>M>L Level 1

              I believe another use case is supplying "-define CONFIG::whatever true"

              options to the compiler.

              (thus use of this immediately scuppers FB-integrated unit testing)

               

              If not possible and there's a feature-request already logged, do say so

              we can vote!

              Cheers, R.

              • 4. Re: Setting compiler options when running unit tests
                mlabriola Level 4

                @R

                 

                Can you get me a project that shows this issue. We use conditional compiler args in FlexUnit 4, so I am not sure why this would break

                 

                Mike

                • 5. Re: Setting compiler options when running unit tests
                  gmaurice Level 1

                  Mike,

                   

                  I have a zip file containing simple projects that illustrate the issue, how should I get it to you?

                  Is there a way to attach files in this forum?

                   

                  Thanks,

                  Gilles

                  • 6. Re: Setting compiler options when running unit tests
                    gmaurice Level 1

                    Here's a simple example of the issue:

                     

                    In project "SimpleLibrary" I have the following classes / constructors:

                     

                    simple.Hello:

                     

                     

                     

                    public function Hello()

                    {

                     

                        var helloWorldClass:Class = getDefinitionByName("simple.HelloWorld") as Class;

                     

                        new helloWorldClass();

                    }

                     

                    simple.HelloWorld:

                     

                     

                    public function HelloWorld()

                    {

                     

                        trace("Hello World");

                    }

                     

                    simple.HelloTest

                     

                    [

                    Test]

                     

                    public function testHello():void

                     

                    {

                        new Hello();

                    }

                     

                    If you right-click and run "Execute FlexUnit Tests" on simple.HelloTest, a FlexUnitApplication.mxml is created and compiled. When it runs, you get the error message: "Variable HelloWorld is not defined" because the class was not pulled in to the swf since it was not explictly referenced.

                     

                    If I create a separate application project and use the compile time option: "-include-libraries ..\SimpleLibrary\bin\SimpleLibrary.swc" to ensure that all classes are included in the swf, then the application runs fine.

                     

                    What I need to do is to have the "-include-libraries" compile time option in effect when FlexUnitApplication.mxml is compiled into a swf.

                     

                    We have other scenarios where the test app needs different compile options than the library. If we can't find a good solution this make the right-click / "Execute FlexUnit Tests" facility of little for us which would be unfortunate since it's very useful.

                     

                     

                     

                    • 7. Re: Setting compiler options when running unit tests
                      mlabriola Level 4

                      If you need to have different libraries / compiler options defined when you run your app versus when you run your unit tests, then your only choice is to

                      use the second option I mentioned before.

                       

                      You can have two projects, one with your application and one for running unit tests. The unit test project can reference the source path from the original project.

                       

                      In Flash Builder, there is no such idea as per Application compilation options, only per project. So, the only way to have a separate set of options in Flash Builder is to have two projects, altough they are still allowed to share the same source.

                       

                      Make sense?

                      Mike

                      1 person found this helpful
                      • 8. Re: Setting compiler options when running unit tests
                        gmaurice Level 1

                        Yes Mike, it makes sense. I wanted to see if there were other options but we'll have to do what you suggested.

                         

                        Thanks for your help.

                        Gilles