FlexUnit 4 und TeamCity

25. February 2010

In an earlier blog article we described how we integrated testing into our process.

In the meanwhile a lot changed. First we switched from FlexUnit to funit which seemed much more lightweight and came with out-of-the-box support. Then FlexUnit 4 came up and IntelliJ IDEA 9 was released including a built-in FlexUnit runner. That alone would have been reason enough to switch over again, but additionally FlexUnit 4 seems to be a huge improvement over the 0.9 predecessor.

Since FlexUnit 4 is now based on JUnit 4.5 it was a snap to port the TeamCityListener from funit over to FlexUnit, and since Hamlet complained last time on how we share code I this time did a fork of FlexUnit on github and applied my patch there.

Everything works great now!

Tags: , , , ,
  1. Mike
    27. April 2011 at 04:37 | #1

    Hi Harald, I’m just taking a look into this now and was wondering if you could explain how you are running your tests under TeamCity?

    We’re using ant with the flexunit ant task here and the tracing to std out by the TeamCityListener is not getting picked up. How do you get this trace into the TeamCity logs using ant?

    Thanks,
    Mike

  2. 27. April 2011 at 09:13 | #2

    @ Mike

    You have to add the listener to your test runner manually:


    private function run():void {
        var core:FlexUnitCore = new FlexUnitCore();
        core.addListener(new TeamCityListener());
        core.run(LibraryTestSuite);
    }

    other than that, we don’t do anything special, we just run the swf within the flashplayer within ant with:


    <exec executable="${player.home}/flashplayer">
        <arg line="${bin.dir}/TeamCityTestRunner.swf"/>
    </exec>

    Cheers,
    Harald

  3. Mike
    28. April 2011 at 02:54 | #3

    @ Harald Radi

    Thanks Harald, I had part one in place but was using flex ant task to build.

    Switching over to use exec I’m noticing that the flash player will not obviously close once tests are complete.

    Our build process compiles a number of test swfs so this means the build will freeze up unless we spawn a new player instance for each test. We then need to kill these at the end of the build. This raises an issue if the tests aren’t complete when we do the final kill.

    How do you get around closing the player once tests are complete?

  4. Mike
    28. April 2011 at 03:45 | #4

    Just looking over your source I see you call fscommand(“quit”); once the tests are complete. Not sure why this isn’t closing the standalone player for me. I’ll recompile and do some digging.

  5. Harald Radi
    28. April 2011 at 04:41 | #5

    @ Mike

    The player should actually close itself properly, the only hint i could give is not to use other listeners together with the TeamCityListener as they could prevent the player from closing properly.

  6. Mike
    28. April 2011 at 05:03 | #6

    OK so I’ve got everything in place like you said but still no trace output from the flash player to the teamcity logs. If I run the ant script locally I don’t see any trace output either, just:

    Buildfile: C:\\build.xml
    test:
    testClean:
    testCompile:
    [mxmlc] Loading configuration file C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\frameworks\flex-config.xml
    [mxmlc] C:\\test\flexUnit-runner\ShellUnitTestRunner.swf (737742 bytes)
    testRunner:
    BUILD SUCCESSFUL
    Total time: 5 seconds

    The runner task is exactly like you specified above and opens, runs and closes the test swf.

    If I run the tests under FlashBuilder I see the teamcity traces as expected. Also worth saying that if I add the XMLListener I can confirm the tests do run when compiling through Ant.

    Sorry for the repeat updates. Any pointers appreciated on how to get trace out through Ant.

  7. Mike
    29. April 2011 at 02:48 | #7

    Just to close this off, I’ve update your TeamCityListener to broadcast results over a socket and updated FlexUnitTask with an option to prints what it receives to std out. This is all working great now. If I get a sec this weekend I’ll do a fork with these updates on githhub.

    Cheers,
    Mike

  8. Jay
    27. June 2011 at 21:38 | #8

    Hey Mike,

    Did you ever fork and make these changes to the TeamCityListener?

    Thanks,
    Jay