antairjenkinscontinuous-integrationflexunit4

ANT-Task for FlexUnit for AIR Mobile project in Jenkins


I am building a Mobile application with Flex 4.11.0 and AIR 4.0. My IDE is Flash Builder 4.7. I wrote a lot of unit tests, some of them using AIR features such as File system access.

I am trying to integrate the project into a CI job on jenkins. I have an ANT script doing the following:

What I want now is to write an ANT-Task to launch my unit tests and generate a report in XML or HTML which can be parsed by Jenkins afterwards.

I have tried the following: - Followed the tutorial on http://tutorials.digitalprimates.net/flexunit/Unit-16.html and got the example to work. However, this is a Flash project and not an AIR-Project! - Read the documentation on https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task, downloaded and built the FlexUnit code from git@github.com:flexunit/flexunit.git to get the FlexUnit4AIRCIListener.swc - Read a LOT of information on the internet from all over the place, not finding an answer (I did find some hints, but a lot of the information is outdated or references dead links)

What I have so far is the following:

<taskdef resource="flexUnitTasks.tasks" classpath="${basedir}\libs\flexUnitTasks-4.1.0.jar" />

<target name="test" >
    <echo>Testing...</echo>
    <echo>==========</echo>

    <!-- 1. Compile FlexUnit-Application -->
    <mxmlc file="${PROJECT.src}\FlexUnit.mxml" output="FlexUnit.swf" >
        <load-config filename="D:\tools\sdk\flex\4.11.0_AIR4.0\frameworks\air-config.xml" append="true" />

        <source-path path-element="${PROJECT.src}" />
        <source-path path-element="${basedir}\test" />
        <library-path dir="${PROJECT.libs}" append="true">
            <include name="**/*.swc" />
            <include name="**/*.ane" />
        </library-path>
        <library-path dir="D:\tools\sdk\flex\4.11.0_AIR4.0\frameworks\libs\air" append="true">
            <include name="airglobal.swc" />
        </library-path>
        <compiler.verbose-stacktraces>true</compiler.verbose-stacktraces>
        <compiler.headless-server>true</compiler.headless-server>
    </mxmlc>

    <!-- 2. Run the compiled SWF -->
    <flexunit swf="FlexUnit.swf" 
                    player="air"
        timeout="180000"
        toDir="${OUTPUT.root}\flexUnit" 
        haltonfailure="false" 
        verbose="true" 
        localTrusted="true"
    />

    <!-- 3. Generate readable JUnit-style reports -->
    <junitreport todir="${OUTPUT.root}\flexUnit">
        <fileset dir="${OUTPUT.root}\flexUnit">
            <include name="TEST-*.xml" />
        </fileset>
        <report format="frames" todir="${OUTPUT.root}\flexUnit\html" />
    </junitreport>
</target>

Here are the relevant parts of my FlexUnit.mxml-Application:

        protected function onCreationComplete(event:FlexEvent):void
        {
            core = new FlexUnitCore();
            core.addListener(new AirCIListener());
            core.run(currentRunTestSuite());
        }
        public function currentRunTestSuite():Array
        {
            var testsToRun:Array = new Array();
            testsToRun.push(test.suites.CLXSatelliteTestSuite);
            return testsToRun;
                    }

Step 1. from the ANT-Task works (at least I get the FlexUnit.swf). However, Launching the SWF in the <flexunit>-Task fails:

VerifyError: Error #1014: Class flash.filesystem::File could not be found.

Console output: [flexunit] Generating default values ... [flexunit] Using default working dir [D:\workspaces\flex\projects\clx-satellite] [flexunit] Using the following settings for the test run: [flexunit] FLEX_HOME: [D:\tools\sdk\flex\4.11.0_AIR4.0] [flexunit] haltonfailure: [false] [flexunit] headless: [false] [flexunit] display: [99] [flexunit] localTrusted: [true] [flexunit] player: [flash] [flexunit] port: [1024] [flexunit] swf: [D:\workspaces\flex\projects\clx-satellite\FlexUnit.swf] [flexunit] timeout: [180000ms] [flexunit] toDir: [D:\workspaces\flex\projects\clx-satellite\deploy\flexUnit] [flexunit] Setting up server process ... [flexunit] Starting server ... [flexunit] Opening server socket on port [1024]. [flexunit] Waiting for client connection ... [flexunit] OS: [Windows] [flexunit] Launching player: [flexunit] Executing 'rundll32' with arguments: [flexunit] 'url.dll,FileProtocolHandler' [flexunit] 'D:\workspaces\flex\projects\clx-satellite\FlexUnit.swf' [flexunit] The ' characters around the executable and arguments are [flexunit] not part of the command. [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] Stopping server ... [flexunit] End of test data reached, sending acknowledgement to player ...

BUILD FAILED
D:\workspaces\flex\projects\clx-satellite\build.xml:148: 
java.util.concurrent.ExecutionException: could not close client/server socket

When I include a single test which does not use the File-Class, the tests work and I get a similar error (ReferenceError: Error #1065: Variable flash.desktop::NativeApplication is not defined.) but at least the tests run through and I get XML-output. Seems to me like FlexUnit is not really compatible with AIR, although I use player=airin the task.

Does anybody of you have a working example of running Unit Tests with FlexUnit for an AIR Application (possibly a mobile application) through ANT?


Solution

  • Never mind, I figured it out myself and blogged about it in my personal blog: http://www.tiefenauer.info/ci-for-flex-mobile-applications-part-3-performing-unit-tests/

    I described a whole CI process there, just in case anyone has the same problem.