FlexUnit works quite well for testing ActionScript code, but one thing that has been a problem is how to automate the testing. Currently you have to run the tests manually, or go to such lengths as Peter Martin (whose solution is clever, but complex). In this post I outline a possible solution using Apollo and Ant.
I don’t have any possibility to test these ideas it right now, but I thought I should outline the idea here and perhaps someone else will beat me to it.
What I want is to be able to add a target in my Ant build script which will run my tests and fail on error much like it’s possible to do with JUnit and unit testing in Xcode.
My idea is to wrap the following as an Ant task (using
- compile an Apollo application which will run the tests
- run the Apollo application with
- the results of the tests are written to a file
- when the file is created, it is picked up by a
waitfortask which runs in parallel with the
- the results are printed as build messages
- depending on the file contents the build fails or continues
Some comments on the steps:
it would be even better if you could compile your tasks as a runtime shared library which a pre-compiled Apollo app could load.
as long as
adlisn’t available as an Ant task
execwill have to do, but you can wrap it up in a
macrodef, which will be almost the same.
the Apollo app doesn’t need to have a UI, so it would be quite unobtrusive.
3-5. Peter Marins implementation uses a socket connection between the test runner and Ant script, which is a bit over the top for my taste, and the
waitfor tasks exist mainly to support this kind of thing. However, I’m not sure about the format of the output file, it has to be something Ant can work with to determine sucess or failure, and to print it along with the build messages.
- One idea is to use one file for failures and one for sucesses, since we can have two parallel
waitfor, but perhaps it’s not needed, I’m not sure at this point. It would be good if an Apollo application could exit with a non-zero value, but it doesn’t look like it’s possible to me.
Anyway, I hope to be able to look into this in a few days. Hopefully I can wrap it all up in a nice task using
macrodef with minimal external dependencies – but it will have to include a SWC containing the test runner and Apollo application at least.
Suggestions are appreciated.