11 Replies Latest reply: Nov 24, 2011 11:26 AM by flashquartermaster RSS

    Receiving trace()-statements in the TestRunner

    wdeboer

      First of all I would like to say I am totallynew to the use of unit testing in general. I am currently evaluating FlexUnit and using the TestRunner.mxml for running the tests. I am only curious how I can let the FlexUnit ant task also show my trace()-statements. Because that makes it easier to fix issues in the code. Now I need to switch the normal application and compile it to check the trace output in the console. Only for working on the implementation and/or fixing one unit test case.

       

      Anyone happen to have some ideas or suggestions how to get this going?

        • 1. Re: Receiving trace()-statements in the TestRunner
          Simeon Bateman Community Member

          You should be able to run the FlexUnit runner in debug mode and get all your normal trace statements from the code that is involved with testing.

           

          Am I missing something about your workflow?

           

          HTH

          sim

          • 2. Re: Receiving trace()-statements in the TestRunner
            wdeboer Community Member

            Hmm, then I have to be doing something wrong because it's not displayed...

            I am using the flexUnit ant task in the following action as noteed below. The DEBUG_MODE is variable is currently set to true and works in the normal application as expecteed.

             

            <target name="unittest">
                    <echo message="Loading the FlexUnit ant task at location: ${BUILDER_DIR}/flexUnitTasks.jar..." />
                    <echo>Executing the unit tests of the project in /tests directory...</echo>
                    <mxmlc file="${TESTS_DIR}/src/TestRunner.mxml" output="${TESTS_DIR}/TestRunner.swf"
                            actionscript-file-encoding="UTF-8"
                            incremental="false"
                            debug="${DEBUG_MODE}" strict="true" optimize="true"
                            use-network="${NETWORK_ACCESS}"
                            default-frame-rate="${FRAME_RATE}"
                            default-background-color="${BACKGROUND_COLOR}">
                      <source-path path-element="${APP_ROOT}" />
                      <source-path path-element="${LIBRARY_SRC_DIR}" />
                      <library-path dir="${LIBRARY_SWC_DIR}" append="true">
                          <include name="*.swc" />
                      </library-path>
                      <library-path dir="${TESTS_DIR}/lib" append="true">
                          <include name="*.swc" />
                      </library-path>
                      <compiler.verbose-stacktraces>true</compiler.verbose-stacktraces>
                      <compiler.headless-server>true</compiler.headless-server>
                    </mxmlc>
            
                    <flexunit swf="${TESTS_DIR}/TestRunner.swf" toDir="${TESTS_REPORTS_DIR}" haltonfailure="false" verbose="true" headless="true" localTrusted="true" />
                </target>
            

             

            If I execute this task I am getting the following output from Apache Ant:

             

            unittest:
                 [echo] Loading the FlexUnit ant task at location: E:\project1\workspace\flash/../dev/automation/flash/flexUnitTasks.jar...
                 [echo] Executing the unit tests of the project in /tests directory...
                [mxmlc] Loading configuration file C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.5.0\frameworks\flex-config.xml
                [mxmlc] E:\project1\workspace\tdd\TestRunner.swf (818409 bytes)
             [flexunit] Validating task attributes ...
             [flexunit] Generating default values ...
             [flexunit] Using default snapshot file path [E:\project1\workspace\tdd\reports\snapshot.jpg]
             [flexunit] Using the following settings:
             [flexunit]     haltonfailure: [false]
             [flexunit]     headless: [true]
             [flexunit]     localTrusted: [true]
             [flexunit]     player: [flash]
             [flexunit]     port: [1024]
             [flexunit]     snapshot: [false]
             [flexunit]     snapshotFile: [E:\project1\workspace\tdd\reports\snapshot.jpg]
             [flexunit]     swf: [E:\project1\workspace\tdd\TestRunner.swf]
             [flexunit]     timeout: [60000ms]
             [flexunit]     toDir: [E:\project1\workspace\tdd\reports]
             [flexunit]     verbose: [true]
             [flexunit]     xcommand: [xvfb]
             [flexunit] Setting up server process ...
             [flexunit] Starting server ...
             [flexunit] OS: [Windows]
             [flexunit] Opening server socket on port [1024].
             [flexunit] Waiting for client connection ...
             [flexunit] Launching player:
             [flexunit] Executing 'rundll32' with arguments:
             [flexunit] 'url.dll,FileProtocolHandler'
             [flexunit] 'E:\project1\workspace\tdd\TestRunner.swf'
             [flexunit] The ' characters around the executable and arguments are
             [flexunit] not part of the command.
             [flexunit] Created local trust file at [C:\Windows\system32\Macromed\Flash\FlashPlayerTrust\flexUnit.cfg]
             [flexunit] Client connected.
             [flexunit] Setting inbound buffer size to [262144] bytes.
             [flexunit] Receiving data ...
             [flexunit] Sending acknowledgement to player to start sending test data ...
             [flexunit] FlexUnit test testDecimals in suite tests.CurrencyHelperTests failed.
             [flexunit] FlexUnit test testRoundingEqual in suite tests.CurrencyHelperTests failed.
             [flexunit] FlexUnit test testRoundingBelowWithinMargin in suite tests.CurrencyHelperTests failed.
             [flexunit] FlexUnit test testRoundingAboveWithinMargin in suite tests.CurrencyHelperTests failed.
             [flexunit] FlexUnit test testThousands in suite tests.CurrencyHelperTests failed.
             [flexunit] FlexUnit test testDecimalsAboveMargin in suite tests.CurrencyHelperTests failed.
             [flexunit] FlexUnit test testRoundingBelow in suite tests.CurrencyHelperTests failed.
             [flexunit] 
             [flexunit] Stopping server ...
             [flexunit] End of test data reached, sending acknowledgement to player ...
             [flexunit] Closing client connection ...
             [flexunit] Closing server on port [1024] ...
             [flexunit] Analyzing reports ...
             [flexunit] 
             [flexunit] Suite: tests.CurrencyHelperTests
             [flexunit] Tests run: 8, Failures: 7, Errors: 0, Skipped: 0, Time elapsed: 0 sec
             [flexunit] 
             [flexunit] Results :
             [flexunit] 
             [flexunit] Tests run: 8, Failures: 7, Errors: 0, Skipped: 0, Time elapsed: 0 sec
            

             

            I am missing the trace()-statement I have in the class which gets tested by the unit test:

             

            trace("decimals=" + ( value - int( value ) ) + " == " + decimalsRounded );
            
            • 3. Re: Receiving trace()-statements in the TestRunner
              Simeon Bateman Community Member

              Ah, see now I get it. I missed that you were using ANT in the first reply.

               

              When using the Stand Alone player you wont get trace output in the command line where the ANT task is running.  You can however configure Flash Player to output the trace statement using a trace file.  It has to do with setting up your mm.cfg file and telling it where to put the output.

               

              At least that is your best bet anyhow.  I have always felt like getting those trace files to work is a vodoo art Maybe someone else will have more input for you on that topic.

               

              HTH

              sim

              • 4. Re: Receiving trace()-statements in the TestRunner
                legrosb Community Member

                @wdeboer - Try creating a file in your home directory named mm.cfg.  Then try putting the following into that file:

                 

                PolicyFileLog=1
                PolicyFileLogAppend=1
                ErrorReportingEnable=1
                TraceOutputFileEnable=1

                 

                I think all trace and error output is now directed to the flashLogs.txt file under

                C:\Windows\system32\Macromed\Flash\Logs

                since you're using Windows.

                 

                Hope this helps.

                 

                -Brian

                • 5. Re: Receiving trace()-statements in the TestRunner
                  wdeboer Community Member

                  Thanks! Maybe the flexunit task can forward the output stream from standalone player? Because when I launch the standalone player via Eclipse it shows the trace()-statements nicely without any hassle. If I find time I will give it a shot myself.

                   

                  For now, I will use the logging file. Thanks again.

                  • 6. Re: Receiving trace()-statements in the TestRunner
                    legrosb Community Member

                    @wdeboer - The integration between Flex/Flash Builder and the Flash movie is much tighter than the integration with the FU4 Ant task.  There is  TextListener in the core that works with the Flex logging framework that you could probably write a UI for to see tests data as it's run.  If you're working with Flex I'd suggest using it over the TraceListener or trace() statements since its more flexible.  If you have time and would like to see something custom, send us a feature request in JIRA and ask others to vote on it.  Best of luck.

                     

                    -Brian

                    • 7. Re: Receiving trace()-statements in the TestRunner
                      wdeboer Community Member

                      Hi  Brian,

                       

                      Yes, I am currently using the TraceListener() together with the FlexUnit ant script. I am considering to update the FlashPlayerCommand in the ant task so it uses:

                       

                           Execute(ExecuteStreamHandler streamHandler)

                       

                      Instead of the simple Execute()-method I think if I keep listening to the output stream of this ExecuteStreamHandler and output it to the task output stream via the LoggingUtil-method then it should all work. I think... I will be experimenting with it with some help from a colleague at work.

                       

                      Thanks,

                      Weyert

                      • 8. Re: Receiving trace()-statements in the TestRunner
                        legrosb Community Member

                        @wdeboer - Thanks for offering to dig in, any help is always welcome.  I encourage you to give it a shot, but I'm unsure if you'll be able to get ahold of the trace output stream from the Flash Player since it's decoupled from the Ant task  It's launched indirectly so you don't have a handle to its pid to do anything with the process.  There maybe be a flag to launch the stand alone Flash Player with the trace output dumping to console, but I have yet to find it.  I know there is a way to attach a debugging session to a Flash Player instance which is probably what Flash Builder does it.  Maybe that would be a good option to try out.

                         

                        If you do have to roll your own thing, we could make a custom socket logger that works with the Ant task and just listens on a separate thread in the Ant task so it can dump to console.  You could probably extend TextListener to make it happend more easiliy; just having to add the socket functionality.

                         

                        In any case, best of luck.  Let me know if I can be of any help.

                         

                        -Brian

                        • 9. Re: Receiving trace()-statements in the TestRunner
                          Michael Labriola Community Member

                          Weyert,

                           

                          Could you explain what you are trying to accomplish. Generally using the trace data is not something I would try to do with Unit tests. If you gave us an idea of what you are trying to accomplish we might be able to offier an alternate approach.

                           

                          Mike

                          • 10. Re: Receiving trace()-statements in the TestRunner
                            wdeboer Community Member

                            First of all my apologies for the late reply.

                             

                            My idea is to write a failing unit test after a ticket with testable issue comes in and then I would like to continously run the unit tests until the issue has been fixed. Instead of running and building the actual application (this has nothing to do with the huge amount of needed mouse clicks ) only then I need to have trace outputs to check debug loggings. For example, I am having a class which formats currency amounts in the proper locale and now I am having an issue with the rounding by five cents. Now I would like to output the differents amounts to spot the error and a few trace()-statements would make that easy.

                             

                            Now I can use flashlog.txt but just seeing it in the console panel in Eclipse is a lot easier and using something like my friends De MonsterDebugger might be overkill for this. Now I have to admit I would love to be able to use breakpoints but my application never stops on breakpoints when using Apache Ant build scripts and Flex Builder.

                             

                            What kind of workflow would you suggest instead?

                            • 11. Re: Receiving trace()-statements in the TestRunner
                              flashquartermaster

                              A straight forward flexunit task e.g.

                              <flexunit player="air"

                                                swf="${tests.swf}"

                                                todir="${report.dir}"

                                                verbose="true"

                                                localTrusted="true"

                                                workingdir="${output.dir}"

                                                />

                              with Dconsol ;http://code.google.com/p/doomsdayconsole/

                              in your library path will output to the console if you use debug/info/warn/error/fatal() instead of trace()

                              import com.furusystems.logging.slf4as.global.debug

                              debug("traces!");