Running unit tests

Skip to end of metadata
Go to start of metadata

Currently flexmojos supports the following frameworks:

Pom dependency

Flexmojos 3.4 and newer versions

On Flexmojos 3.4 the unittest-support dependency is no longer required and actually MUST BE REMOVED from the pom. Now, you only need to add the unit test framework to your dependencies.  This better mirrors how Java/Surefire work.  More details on dependencies GAV here.

Flexmojos 3.3 and previous versions

To activate unit test support, simply add the following dependency to your POM:

<dependency>
  <groupId>org.sonatype.flexmojos</groupId>
  <artifactId>flexmojos-unittest-support</artifactId>
  <version>${flexmojos.version}</version>
  <type>swc</type>
  <scope>test</scope>
</dependency>


Flexmojos requires FlashPlayer to run unit tests.

We recommend using the debug version of the Standalone player (also known as "Projector"). It can be found here.
Direct links:

Once installed, make sure it is available on PATH.

OS Expected executable on PATH Tips
Windows FlashPlayer.exe
  • If you downloaded flashplayer_10_sa_debug.exe then a rename makes sense.
    • The IE and FF plugins end up in C:\Windows\System32\Macromed\Flash so you can choose to put the standalone exe here as well and put the directory on your path.
  • Or specify the path and filename explicitly as noted here.
Mac Flash Player  
*nix flashplayer  

Note 2: On Mac OS, add /${flashplayer.dir}/Flash Player.app/Contents/MacOS/ folder to PATH.

Note: After updating PATH you probably need to restart your CI environment (Bamboo, Hudson etc.)

Alternatives for those who don't want to include flashplayer on PATH
Flexmojos 4.x

The Maven property name was changed from "flashPlayer.command" to "flex.flashPlayer.command". It is a Maven best practice to set system specific properties like this in your settings.xml file rather than your project pom.xml:

<properties>
	<!-- Point to standalone flashplayer -->
	<flex.flashPlayer.command>/opt/flash_standalone/flashplayer</flex.flashPlayer.command>
</properties>
After Flexmojos 3.3

On Flexmojos 3.3 testing support was modularized and created a new component to launch tests. But Maven is no longer able to inject flashPlayer.command on it. So if you rely on that (instead of add to path witch is the recommended approach) you must do this:

<build>
  <plugins>
    <plugin>
      <groupId>org.sonatype.flexmojos</groupId>
      <version>3.3.0</version>
      <artifactId>flexmojos-maven-plugin</artifactId>
      <extensions>true</extensions>
      <configuration>
        <testRunner>
          <launcher>
            <flashplayerCommand>${flashPlayer.command}</flashplayerCommand>
          </launcher>
        </testRunner>
      </configuration>
    </plugin>
  </plugins>
</build>

Once that is on pom flashPlayer.command argument will work again.

Before flexmojos 3.3

Add the following argument on command line -DflashPlayer.command=${flashplayer executable}

Tips for flexmojos + linux + continuous integration

If you are running flexmojos on a headless Linux server you have 2 options:

  1. provide a GUI environment for flashplayer
  2. provide the tools that flexmojos needs to create its own environment
  • install Xvfb and xvfb-run
  • install xvfb-run if not installed with Xvfb server
  • install flashplayer dependencies. On Ubuntu 8.04 server it was necessary to install: libxt6, libgtk2.0-0 and libnss3-1d. The names may vary, depending on the Linux distribution.
  • when using non-root, be aware that the user needs permission to write to 2 folders: ~/.adobe and /tmp/.X11-unix
  • make sure /etc/X11/xserver/SecurityPolicy exists! If does't copy it from /usr/share/doc/examples/SecurityPolicy or download this one.
  • enable flash debugging (take a look here)
  • to run adl on 64-bits linux you will need to do some extra work, check the steps here

Some extra tips from users:

  • add HOME (=/usr/share/tomcat6) variable in /etc/init.d/tomcat6
  • change ~/.Xauthority file ownership and pemission (so that tomcat user can write to it, and owns it)
  • on 64-bit machines, make sure you have the 32 -bit versions of curl and nss installed
  • You can have your build fail with the following error:
    [INFO] [flexmojos:test-run {execution: default-test-run}]
    [INFO] Flexmojos 3.7.1
    [INFO] 	 Apache License - Version 2.0 (NO WARRANTY) - See COPYRIGHT file
    [INFO] Running tests /home/user/project/target/test-classes/TestRunner.swf
    [WARNING] [LAUNCHER] Using regular flashplayer tests
    [INFO] ------------------------------------------------------------------------
    [INFO] Tests run: 0, Failures: 0, Errors: 0, Time Elapsed: 0 sec
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] Read timed out /home/user/project/target/test-classes/TestRunner.swf
    

    This might be caused by a unit test that gives a runtime error (In my case because of 'type coercion failed'). If you have this on your headless CI server, try running the tests manually on your development machine to see if an error dialog pops up.

  • I have had my tests fail with 0 tests run like the previous point, but where the solution was to add this to my settings.xml:
    <properties>
      <flex.flashPlayer.command>flashplayer</flex.flashPlayer.command>
    </properties>
    

    You will need 'flashplayer' on your path ofcourse or you can specify the absolute path as well. This fixed it for running the tests headless and normally.

If you have any other extra tips, please edit this page.

What to do if there is no way to get tests working properly?

Java/Flex integration to run test is solid, but not bullet proof, so there are an infinite number of reasons to it not work as it should. Usually the problem can be in 3 places:

  • Flexmojos
  • User environment
  • User tests

Usually, it is not on Flexmojos. This is a very well tested on an health environment, using some predictable tests. So the most probable places to be causing problems are user environment and/or tests.

The fastest way to know if the environment is correctly setup is running the tests used by Flexmojos during integration tests. They can be found here:

It is necessary to edit the pom and replace %{flexmojos.version} with the desired Flexmojos version.

If the test from Flexmojos works, mean you environment is OK! and Flexmojos is double OK!

Most common problems on user tests are:

  1. Try to replace the template with a broken one;

If you know any other common problem, please edit this page.Download the Windows Flash Player 10.2 Projector content debugger

Using Flash Player Debugger on Mac to run FlexUnit Tests

Flexmojos expects to find an executable file with the name "Flash Player" inside of the Flash Player folder "Contents/MacOS", but the name of the executable file inside debug version is: Flash Player Debugger

To solve this problem, you have to set a symbolic link.

With the following commands, you can install and set symbolic link:

unzip flashplayer_10_sa_debug.app.zip
sudo cp -r Flash\ Player\ Debugger.app /Applications/
cd /Applications/Flash\ Player\ Debugger.app/Contents/MacOS
sudo ln -s Flash\ Player\ Debugger Flash\ Player

Running FlexUnits test using m2e Eclipse Plugin on Mac

Applications with UI (Eclipse or IntelliJ) of MAC haven't access to extended environment variable PATH.

To solve this problem, you have to set the flashPlayer.command in Eclipse so that Maven can launch the Flash Player.

1.Solution: Set the Enviroment Variable in Maven Lauch Configuration of Eclipse.

Eclipse -> Run -> Run Configurations -> Select the Maven Build in the left column -> Environment -> New

Set following values:

Variable: PATH
Value: /Applications/Flash\ Player.app/Contents/MacOS (if the Flash Player is located below "/Applications")

And select the RadioButton: Append environment to native environment

Click "OK" to finish.

2.Solution: Add location of the Flash Player as property to your pom.xml

<properties>
  <flashPlayer.command>/Applications/Flash Player Debugger.app/Contents/MacOS/Flash Player</flashPlayer.command>
</properties>

Tip: If you use Maven profiles, you can use the second solution to target different player versions or different environments (e.g. development evironment, CI)

<profile>
  <id>dev</id>
  <properties>
    <flashPlayer.command>/Applications/Flash Player Debugger.app/Contents/MacOS/Flash Player<</flashPlayer.command>
  </properties>
</profile>

<profile>
  <id>CI</id>
  <properties>
    <flashPlayer.command>/DEVEL/flex/flex_sdk_4.1/runtimes/player/10.1/lnx/flashplayerdebugger</flashPlayer.command>
  </properties>
</profile>
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Apr 06, 2009

    yeudy.molina says:

    Hi Marvin! Do you have plans to support Fluint Framework? Thanks, for all ...

    Hi Marvin!

    Do you have plans to support Fluint Framework?

    Thanks, for all your work, it's very helpfully for all us.

    1. Apr 06, 2009

      Marvin Herman Froeder says:

      Well, fluint doesn't dispatch events, so I can't listen for tests results.... ...

      Well, fluint doesn't dispatch events, so I can't listen for tests results....

      VELO

  2. Apr 21, 2009

    David Hoffer says:

    How to do this in a headless environment, i.e. CI build?  Ideally no flash ...

    How to do this in a headless environment, i.e. CI build?  Ideally no flash player.  Is there a way to configure flash player to run headless?

    1. Apr 23, 2009

      Marvin Herman Froeder says:

      You do need an actionScript virtual machine to run the test.  Currently the...

      You do need an actionScript virtual machine to run the test.  Currently there are 2 real options: Flash Player and Air Player.  Neither run on headless environment.  So, you do need to adapt you env to run this.  The good news is flexmojos already handle that.  You just need xvfb installed (run xvfb-run)

      VELO

      1. May 05, 2009

        yeudy.molina says:

        I tried with flexmojos 3.2-SNAPSHOT and all working fine. Yeudy

        I tried with flexmojos 3.2-SNAPSHOT and all working fine.

        Yeudy

      2. May 25, 2009

        Peter Jacobsen says:

        Hi Marvin, I am using FlexUnit on my continuous integration server (TeamCity) - ...

        Hi Marvin,
        I am using FlexUnit on my continuous integration server (TeamCity) - but the second run always fails. The problem seems to be the xvfb-run script when trying to create a TMP directory for XAuthority - because Xvfb (and flashplayer) are still running. I think that flashplayer fails to exit after running a TestRunner.swf (runs fine on OS-X and Windows).
        Do you have any hint on what/how I schould check? Should I start Xvfb start manually beforehand and would Flex Mojos detect it (start flashplayer only)?

        Thanks and Regards,
        Peter

  3. Jun 30, 2009

    aetuo7964 says:

    Hi  Do you have plans to support FlexUnit 4 ?

    Hi

     Do you have plans to support FlexUnit 4 ?

    1. Jun 30, 2009

      Marvin Herman Froeder says:

      Yes, but doesn't even start scratching it. VELO

      Yes, but doesn't even start scratching it.

      VELO

  4. Jul 22, 2010

    Arthur Vernon says:

    I have been trying the 4.0 aplha version and it appears as though the name of th...

    I have been trying the 4.0 aplha version and it appears as though the name of the property for the flash player commmand has changed.

    <properties><flex.version>4.0.0.14159</flex.version><flex.mojo.version>4.0-alpha-3</flex.mojo.version><flash.player.version>10.0.0</flash.player.version><flex.flashPlayer.command>flashplayer_10_sa_debug.exe</flex.flashPlayer.command>

    <!--  doesn't work <flashPlayer.command>flashplayer_10_sa_debug.exe</flashPlayer.command> -->

    </properties>

    Is this correct? Tests now appear to run, rather than failing with a message indicating FlashPlayer.exe is not on the classpath.