FlexUnit4 Test Suite Generation

6 views
Skip to first unread message

jonnyreeves

unread,
Jan 31, 2010, 8:50:17 AM1/31/10
to Antennae Discussion
Hi Chaps,

I've been working to fully integrate FlexUnit4 with Antennae (ie: full
metadata support rather than using the FlexUnit 0.9 falbacks).

In order to do this I have made some changes to the build-properties
file and the arc-flexunit.jar java sources (to generate a FlexUnit4
style "TestSource" file.

What would be the best way of submitting my changes for review, or
does the antennae project not intend to migrate to FlexUnit4?

Thanks
Jonny.
http://jonnyreeves.co.uk/

Gareth Arch

unread,
Feb 1, 2010, 8:18:38 AM2/1/10
to Antennae Discussion
I actually put something together to do this already (described in the
thread below this one in http://groups.google.com/group/antennae-discussion/browse_thread/thread/4ed1e2f995595560)
and made a patch for it (in the "files" link for this group), but was
just waiting for a review myself. I wouldn't mind checking it out
your code to see if anything overlaps or see if there was anything I
could update in my code.

jonnyreeves

unread,
Feb 2, 2010, 12:41:35 PM2/2/10
to Antennae Discussion
Hi Gareth,

Thanks for your post, it provided me with the initial motivation to
get FlexUnit4 working under antennae. I didn't do a lot different to
you, the only parts which you hadn't documented were passing the
metadata tags to the mxmlc compiler and modifying the arc-flexunit.jar
file to generate a FlexUnit4 style TestSuite template.

To keep the metadata, I added a new reference to build-common-
properties.xml:

{{{
<resources id="flexunit.metadata.ref">
<resource name="RunWith" />
<resource name="BeforeClass" />
<resource name="AfterClass" />
<resource name="Before" />
<resource name="After" />
<resource name="Suite" />
<resource name="Test" />
<resource name="TestCase" />
<resource name="Ignore" />
<resource name="Filter" />
<resource name="Sort" />
<resource name="Theory" />
<resource name="DataPoint" />
<resource name="DataPoints" />
<resource name="ArrayElementType" />
</resources>
}}}

I then pass this to the mxmlc macro via the options param like this:

{{{
<pathconvert property="_flexunit.metadata"
refid="flexunit.metadata.ref" pathsep=" ">
<mapper type="glob" from="*" to="-keep-as3-metadata+=*" />
</pathconvert>
}}}


Finally, I modified the java sources of arc-flexunit.jar
(AllTestsFileGenerator.java) to produce the new style of TestSuite
class (which again relies on Metadata rather than inheritence), the
contents of the jar file ended up looking a bit like this:

{{{
// generate the class
StringBuffer result = new StringBuffer();
result.append("package");
result.append("\n{");
result.append("\n import flexunit.framework.*;");

Iterator classes = classlist.iterator();
while (classes.hasNext())
{
result.append("\n import " + classes.next() + ";");
}

result.append("\n\n [Suite] ");
result.append("\n [RunWith(\"org.flexunit.runners.Suite\")]
");
result.append("\n public class FlexUnitAllTests ");
result.append("\n {");

classes = classlist.iterator();
int i = 0;
while (classes.hasNext())
{
i++;
result.append("\n public var t" + i + " : " + classes.next
() + ";");
}

result.append("\n }");
result.append("\n}");
}}}

The whole process works pretty well for me, I get full FlexUnit4
support with the added benefit of an autogenerated TestSuite (and it's
also possible for users to create their own should they want a bit
more control). One of the things I'm most pleased about is that you
can open the resulting TEST-*.xml files in the JUnit view in eclipse
which almost makes the integration feel as tight as FlashBuilder 4 :)

Let me know if you want me to upload any files / patches to the group
or if you have found any other neat tricks?

Jonny.

Reply all
Reply to author
Forward
0 new messages