FlexUnit4

17 views
Skip to first unread message

Gareth Arch

unread,
Nov 13, 2009, 11:59:11 AM11/13/09
to Antennae Discussion
Just wanted to start by saying great work on this. Once I got the
structure down (took me a little bit to wrap my head around all of the
includes, assets, variables, etc.), the implementation is very
straight-forward.

Anyway, back to my reason for the post:

At my job, we recently began implementing unit testing on our flex
code and have since started using FlexUnit4. Currently in Antennae,
it seems to be using FlexUnit1 when calling any of the "test" targets.

I downloaded FlexUnit4's CI project and have got FlexUnit4 working
with Antennae (I've changed the mxmlc to use Antennae's macrodef
rather than using the flexTasks.jar file that is included in FU4's CI
example project). I didn't know whether this was going to be included
in a later Antennae build or even whether others were interested in
what is necessary to get this working with FU4, but thought I would
post to find out.

If anyone's interested, I can post the (very minimal) changes
necessary to get FlexUnit4 up and running with Antennae. It's
currently all in my build.xml file, but could (and I'm sure should) be
moved into the build-common-targets.xml file. FU4 is backwards
compatible with FU1, so it wouldn't seem to be too large of an impact
on old test cases.

Daniel Rinehart

unread,
Nov 15, 2009, 10:48:40 PM11/15/09
to antennae-...@googlegroups.com
I know I would be interested in seeing the changes that you have made
even if they are in a rough form. FU4 is getting stable enough that I
can see it starting to be used regularly.

-- Daniel R. <dan...@neophi.com> [http://danielr.neophi.com/]
> --
>
> You received this message because you are subscribed to the Google Groups "Antennae Discussion" group.
> To post to this group, send email to antennae-...@googlegroups.com.
> To unsubscribe from this group, send email to antennae-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/antennae-discussion?hl=.
>
>
>

Gareth Arch

unread,
Nov 16, 2009, 1:53:51 PM11/16/09
to Antennae Discussion
OK, I started to modify the build-common-targets.xml and the build-
assets.xml files and started to realize all of the things I'd have to
change to get it working, so I thought I'd just post my build.xml file
for now, then modify that stuff later :)

This compiles my utilities library using the TestRunner.mxml file,
into a TestRunner.swf Flexunit runs the generated TestRunner.swf then
outputs xml files to the specified reports dir. junitreport then
generates some nice looking reports from this xml.

Just have to add in the new flexunit4 swcs (flexunit-4.0.0.swc,
FlexUnit4CIListener.swc, flexunit-uirunner-4.0.0.swc) to the build,
the flexUnitTasks.jar file (for the <flexunit> and <junitreport>)

Here's all that's neeeded to get the testing working in flexUnit4:

<project name="utilities" basedir="." default="test">
<!-- Project specific overrides -->
<property name="root" value="." />
<property name="main.src.loc" location="${basedir}/src/main/flex" />
<property name="test.src.loc" location="${basedir}/src/test/flex" />
<property name="lib.loc" location="${basedir}/lib" />
<property name="bin.loc" location="${basedir}/bin" />
<property name="report.loc" location="${basedir}/report" />
<property name="src.flex.dir" value="src/main/flex" />
<taskdef resource="flexUnitTasks.tasks" classpath="${lib.loc}/
flexUnitTasks.jar" />

<import file="build-imports.xml" />

<!-- Build path -->
<path id="flex.lib.path">
<pathelement location="${root}/lib/flexunit-4.0.0.swc" />
<pathelement location="${root}/lib/FlexUnit4CIListener.swc" />
<pathelement location="${root}/lib/flexunit-uirunner-4.0.0.swc" />
</path>

<!-- Project specific targets -->
<target name="test">
<!-- Compile TestRunner.mxml as a SWF -->
<mxmlc
src="${test.src.loc}/TestRunner.mxml"
src.path="${main.src.loc}"
dest="${bin.loc}/TestRunner.swf" />
<!-- Execute TestRunner.swf as FlexUnit tests and publish reports --
>
<flexunit swf="${bin.loc}/TestRunner.swf" toDir="${report.loc}"
haltonfailure="false" verbose="true" localTrusted="true" />

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

On Nov 15, 10:48 pm, Daniel Rinehart <dani...@neophi.com> wrote:
> I know I would be interested in seeing the changes that you have made
> even if they are in a rough form. FU4 is getting stable enough that I
> can see it starting to be used regularly.
>
> -- Daniel R. <dani...@neophi.com> [http://danielr.neophi.com/]

Gareth Arch

unread,
Nov 16, 2009, 2:12:12 PM11/16/09
to Antennae Discussion
Argh! Forgot a couple of things with this...

Here's my TestRunner.mxml page. The lines
core.addListener( new UIListener( uiListener ) );
core.addListener( new CIListener() );
allow the app to report back to the ant build when the testing is
complete. This is just taken from the test CI project in FlexUnit4.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:flexUnitUIRunner="http://www.adobe.com/2009/flexUnitUIRunner"
creationComplete="runTests();"
layout="absolute">

<mx:Script>
<![CDATA[
import mx.logging.LogEventLevel;
import org.flexunit.internals.TextListener;
import org.flexunit.internals.TraceListener;
import
com.flexoop.lib.components.arraycollection.PagedArrayCollectionTest;
import org.flexunit.listeners.CIListener;
import org.flexunit.listeners.UIListener;
import org.flexunit.runner.FlexUnitCore;

public function runTests() : void {
var core:FlexUnitCore = new FlexUnitCore;

/**If you don't need graphical test results, comment out the line
below and the MXML declaring
the TestRunnerBase. **/
core.addListener( new UIListener( uiListener ) );
core.addListener( new CIListener() );

/**If you would like to see text output in verbose mode, umcomment
either of the follow listeners **/
//core.addListener( new TraceListener() ); - For AS3 Projects
//core.addListener( TextListener.getDefaultTextListener
( LogEventLevel.DEBUG ) ); - For Flex Projects

core.run( PagedArrayCollectionTest );
}
]]>
</mx:Script>
<flexUnitUIRunner:TestRunnerBase id="uiListener" width="100%"
height="100%" />
</mx:Application>

Gareth Arch

unread,
Nov 17, 2009, 12:19:51 AM11/17/09
to Antennae Discussion
Hmmm, I ran into a slight snag. For some reason, the errors are being
output to the console, rather than to an xml file. The success is
fine, those get written to the xml files, but not the failures. I
think it is related to the mxmlc creation, as I can switch to a
different TestRunner.swf that I created for the FlexUnit4CI Project,
and it outputs correctly (it shows

[flexunit] Suite: test.com.flexoop.utilities.dateutils.WeekOfYearTest
- Tests
run: 1, Failures: 1, Errors: 0

but outputs the "Failures: 1" data to an xml file, rather than to the
console).

Anyone have any ideas of what I need to alter to get it to work?

Daniel Rinehart

unread,
Nov 18, 2009, 10:06:44 PM11/18/09
to antennae-...@googlegroups.com
That's odd that only one of the two streams is getting written to the
log file. I'll try to poke at this tomorrow and see if I notice
anything odd.

Gareth Arch

unread,
Nov 19, 2009, 9:57:13 AM11/19/09
to Antennae Discussion
Hey Daniel,
Don't worry about your testing. I began stripping down my unit tests
and it looks like it's something with FU4. I found that if I put
single quotes in my description for the Assert statement (e.g.
Assert.assertEquals( "validate that next moves to next 'page'", 2,
1 ); ), and the unit test fails, it bombs out. It outputs to the
console, but doesn't create the XML. It probably tries to create the
XML, fails, so it outputs to the console, but also stops processing
anything else. If the method *passes*, then it works fine (I guess as
it doesn't have to create the xml with the single quotes).

Also, I've finished making changes to the base antennae files for my
testing, and have added the new targets to the build-common-
targets.xml file (flex-test-application-flexunit4, and flexunit4-test-
report), added the flexUnitTasks resource to the build-common-
tasks.xml file (still not sure how best to handle this one though),
made a small change to the mxmlc macrodef argument order to allow for
a single paged application to be built, and added a couple more
properties to the build-common-properties.xml file. Let me know if
you would like the patch to check it out.

Thanks,
Gareth

On Nov 18, 10:06 pm, Daniel Rinehart <dani...@neophi.com> wrote:
> That's odd that only one of the two streams is getting written to the
> log file. I'll try to poke at this tomorrow and see if I notice
> anything odd.
>
> -- Daniel R. <dani...@neophi.com> [http://danielr.neophi.com/]

Daniel Rinehart

unread,
Nov 20, 2009, 7:43:22 AM11/20/09
to antennae-...@googlegroups.com
Wow, that's a subtle bug, glad you were able to track it down.

Passing along a patch of your changes would be great. Thank you for
taking the time to look into this.

Gareth Arch

unread,
Nov 20, 2009, 10:11:23 AM11/20/09
to Antennae Discussion
I uploaded the patch to the files section of the google group.

Reasons for updates:
build-common-properties.xml
This one sets a default for the test directory (however, if they
change the default source directory from src, this will be off e.g. if
src.flex.dir is src/main/flex, then this value will get set to src/
main/flex/test/flex, so this may need to be rethought a little. I
ended up setting the test and main directories in my build.xml file
each time, but I thought this might be a timesaver for people if they
use src as their main build directory)
I also added a couple of flexunit4 properties for a report directory
and a name for the main testrunner file and swf that is generated.

build-common-targets.xml
added the report directory to the initial directory creation.
added the flexunit4 app creation and report creation targets. Report
creation depends on app creation.

build-common-tasks.xml
moved the +flexlib higher up in the arguments as this was throwing an
error if the project contains a single application file and no other
files. I don't think this will affect the creation at all, but wanted
to note it.
added the taskdef tag. This one will probably need to be rethought a
little. I added this value to the build.xml file when I'm running my
unit testing as it needs to point to the jar file. I had it in assets
originally, but of course, that was getting added to the script after
this value has attempted to be set and was failing as it could find
the location. I'm open to ideas on where/how to set this (as I'll
need to modify my local files also). I found that this file can be
compiled via javac from the FlexUnit4 files at github, so perhaps this
set of files could be added to the initial build of files necessary
for Antennae (then updated as they fix any bugs they find in
FlexUnit4)?

Anyway, just wanted to explain my thoughts behind this stuff. Hope it
helps.
Gareth

On Nov 20, 7:43 am, Daniel Rinehart <dani...@neophi.com> wrote:
> Wow, that's a subtle bug, glad you were able to track it down.
>
> Passing along a patch of your changes would be great. Thank you for
> taking the time to look into this.
>
> -- Daniel R. <dani...@neophi.com> [http://danielr.neophi.com/]
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages