Flash Builder 4.5 & FlexUnit 4.1

We have a large multi-module product that we are writing in Flex 4.1, running on top of mid-level Java.

Based on the Java background, I want to have support in the Flex environment for writing and running unit tests.

I updated Flash Builder 4.5 with the release of FlexUnit 4.1, and I can write and execute unit tests successfully in an application project, but I have not developed how to get unit tests working on unit or library projects in Flash Builder.

Problems with library projects

Since we need tests compiled for the application (SWF), I need to either create a companion project project in Flash Builder, or change the type of links in the library project dependencies (SWC) to avoid external ones, because external dependencies are expected to be made by someone else (usually this is a top level application).

As an experiment, I tried to change the binding in a project with a model library: the SWF test runner was successfully generated, but FlexUnit could not start it, because error # 1065 was reported about something that made no sense to me.

For our build without headless (using Gradle), I found this easy to solve by simply merging all the dependencies, regardless of their original connection when creating the SWF test runner. I can also easily run this from Eclipse using external tool support, as the result is JUnit-compatible XML results that appear in the normal JUnit view.

How do you do this?

How do other Flex developers structure their unit tests in a multi-module and multi-library project? Are you running tests from Flash Builder 4.5? Can you run tests yourself for any library project or module?

+4
source share
1 answer

OK, this is the second time I answered my question (the latter was also around Flex).

I went to add tests to each individual project, but I run tests from a central test project.

Each project should have:

  • test catalog
  • MLXML application with naming convention <project name>Test.mxml in the test directory
  • a set of top-level tests that combines all the tests in the project under the test directory in the usual package structure
  • some unit tests; -)

Flash Builder does not like MXML applications that live in any directory other than src , so it is important NOT to set the test directory as another source directory.

Now add the source test directories from each project to the overall test project. You will need to add all the necessary dependencies (both runtime and test) to this project.

I find FlexUnit a little weird in how it runs a runner for unit tests. He will suggest creating a test application for the MXML tester when you select "run as → Flex Unit Tests" in Eclipse (you can choose which tests it should run). Selecting "Execute FlexUnit Tests" from the context menu does not cause MXML generation.

You should not check this MXML file for the original control, but ignore it. The reason is that FlexUnit does not regenerate this file successfully if you want to run a different set of tests. This means that you need to manually delete the file when you want to generate it.

Here is an example of MXML that we use for a test runner in a library project:

 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="onCreationComplete()"> <fx:Script> <![CDATA[ import net.infonic.hs.AllTestsSuite; import org.flexunit.listeners.CIListener; import org.flexunit.runner.FlexUnitCore; private var core: FlexUnitCore; public function currentRunTestSuite(): Array { var testsToRun:Array = new Array(); testsToRun.push(AllTestsSuite); return testsToRun; } private function onCreationComplete(): void { core = new FlexUnitCore(); core.addListener(new CIListener()); core.run(currentRunTestSuite()); } ]]> </fx:Script> </s:Application> 
+2
source

All Articles