Skip to content

Flexunit Ant Tasks, [flexunit] error while loading initial content, compiler flags and other handy stuff.

After spending almost entire day getting Flex Unit tasks sorted I decided to write what I discovered, it is really takes a bit of time to sort it out.

So I want to have an ant task that is going to execute flexunit task, that will run on a Linux without Flash Player, but will have AIR. I actually havent verified the last part because I only got it working locally.
Dropping it onto the linux box now should not be a problem.

So what do you need?
FlexUnit of course, you probably have it already if you are running unit tests, so I am not going to go there. Just make sure you have the latest version.

Ant specific documentation can be found here:

Let’s start with the version number. Make sure you have the latest version, also make sure you have the latest of taskDefinitions

You should define flex unit tasks in your build file:

<taskdef resource="flexUnitTasks.tasks"

Mine is pointing to “lib/flexunit/flexUnitTasks-4.1.0-8.jar”

Versioning is quite important, I was pointing to “lib/flexunit/flexUnitTasks-4.1.0-beta1.64.jar”
previously and was getting some strange errors like

[flexunit] error while loading initial content

Which only happened when I changed Flex SDK from 4.1 to 4.5.
It turns out that the beta version has got a template inside that creates default app descriptor for AIR 1.5.
Changing it to 3.1 adding version number does the job, but like I said it is probably easier to pull the latest version and not worry about the template in the jar file at all.

Once we have our tasks defined we can use flexunit tag:

    <source dir="${SRC_ROOT.dir}" />
    <testSource dir="${TESTS_ROOT.dir}">
        <include name="**/*" />
    <library dir="${BUILD_FILES.dir}" />

Once again it all explained here:

If you want to add conditional compilation flags you then should go and edit your flex-config.xml or air-config in your SDK/frameworks folder

In the compiler tag add


There is a line in the docs that says:

Note: a custom built version is available that also allows you to pass compiler constants (like SOMETHING::something=something). Read about it in the discussion section (link at the top of the page).

but I did not want to go there, to get another version that potentially breaks something else. Compiler definition is good enough for me.

I also noticed some weird errors people are getting going flash route (player=”flash”).

That does look something like that

VerifyError: Error #1014: Class could not be found.

    at flash.display::MovieClip/nextFrame()
    at mx.managers::SystemManager/deferredNextFrame()
    at mx.managers::SystemManager/preloader_preloaderDocFrameReadyHandler()
    at mx.preloaders::Preloader/timerHandler()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

which does not occur when player is set to AIR. So overlay your Flex SDK with AIR, set the player to AIR and it should make it go away.

It was a bit time consuming checking all the versions, investigating problems I came across and hopefully with this post things will be a bit clearer.

UPDATE: If you are getting problems with UIImpersonator throwing errors make sure you point to
as3 version of flexunit swc not the flex one.

Posted in development.

Tagged with , , , , , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.