views:

278

answers:

4

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).

+1  A: 

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)

inferis
No, you can choose which files to compile into your library SWC (project properties -> Flex Library Build Path).
Darscan
A: 

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.

James Ward
A: 

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.

Rani
+1  A: 

So to expand on the above answer, the step-by-step to be able to test your library project, with debugging enabled (you can't run the debugger when you just 'Run Flexunit Tests' on your library) goes something like:

  1. Create your Flex Library project
  2. Create a normal Flex Application
  3. Set the library build-path to the libs folder of the Flex Application (At least while you test, so any changes you make to the library are automatically updated in the Flex App, saves headaches and much copy/pasting of swc file)
  4. Optionally, set the Flex Application to 'reference' the library project in Project Properties->Project References, this ensures the library is built first. (Though I've never had any issues, see 2nd last heading: http://tinyurl.com/yco4y2x)
  5. Write your tests in the Flex Application linking to the library
  6. Debug your tests and you should be able to step through your source code!
  7. Optionally, copy your tests back into the library project when you're done, just to keep all the library's associated code together. Though make sure you're not including these test classes in the actual library swc.

This is how I do it anyway.

secoif