3
votes

For a normal Flash/Flex application I would include my Unit Tests in my application project (perhaps in a tests source folder alongside my main src folder). I'd then have two application entry points: the app, and it's tests.

How are people doing this for their Flex Library Projects? You know, the kind that produces a SWC file. As far as I can tell, you can't set an executable entry-point for these projects (to run the tests).

4

4 Answers

6
votes

Normally, Flash Builder only allows you to use the debugger from a Flex/AIR application, not a library project. So best thing to do here is load the library into a Flex application and write+debug tests there.

Here are step-by-step instructions to be able to test your library project, with debugging/stepping enabled:

  1. Create a Flex Library project that you want to test + debug
  2. Create a normal, empty Flex Application. We will write the tests in this dummy Flex Application so we can utilise the debugging features.
  3. Set the library's build-path to the 'libs' folder of the Flex Application so it builds most recent code into a swc loaded by the Flex Application.

  4. Optionally, set the Flex Application to 'reference' the library project in Project Properties->Project References, this ensures the library code is built first.

  5. Write your tests in the Flex Application
  6. Debug and run your tests: you should be able to step through your library source code! Nice.
  7. Optionally, once you're satisfied your tests are all good copy your tests back into the library project to keep all the library's associated code together in one project. Make sure you're not including the test classes in the actual library swc.

This is how I do it anyway.

2
votes

If we assume that you need an mx:Application entry point to run the unit tests, then it would seem to make sense to generate a separate application project solely to run the tests.

Would you really want to include the unit tests in the compiled SWC anyway? (For an application this wouldn't be a problem since they're, presumably, not referenced, but for a SWC library I think they'd be compiled in if they're in the folder hierarchy somewhere)

1
votes

In Flash Builder Beta 1 onwards itself, you can write and execute Flexunit tests from a library project.

You can use the IDE integration feauture of FlexUnit, and select the project, folder , class or method from the context menu and use "Execute Flex Unit Tests". This will create the application file of the required syntax, run the application and show the results in the FB. You can even select from the result and run the tests are requried.

1
votes

There isn't currently a way to test a library project. You must have an application as the entry point to the tests. This would be a great feature request for Flash Builder 4.