I really like the fact that FlexUnit is built right into Flash Builder since one of the main reasons unit testing used to fall off our radars was it was a pain setting up Flex Unit and executing scripts. However one of the things that struck me pretty weird was that Flash Builder was writing tests in the source directory. Best practices in unit testing say that the tests should be in a separate folder called tests/ which should be a sibling of the src/ folder. This lets the tests be written with the same package as the code being tested. This allows, for example, testing functions with a package level visibility.
The correct way to get this working is, when starting the project add another folder called tests for the build path. Now Flash Builder will look at both the source and the tests path when looking for .as files. To write a unit test Test Case, right click on the tests folder and click on the new Test Case option.
[Update] I have filed a bug in Adobe’s ticketing system to track this issue. Please vote for it if you agree: http://bugs.adobe.com/jira/browse/FXU-50
Great explanation of a best case scenario. I am writing a lot more tests these days, and this tip will help me setup my code better. Thanks.
LikeLike
“However one of the things that struck me pretty weird was that Flash Builder was writing tests in the source directory”
This is changable in FB. In wizard which is opened for the testCase class and test Suite class creation user can change the Source Folder and package. (I accept that now for every time creation, it will put the default value). If you prefer to make this configurable, please file an enhancement request in http://bugs.adobe.com/jira under the FlashBuilder – flexunit.
LikeLike
For details of FlexUnit integration in Flash Builder please refer http://balajisridhar.wordpress.com/
LikeLike
Thanks Rani, done! http://bugs.adobe.com/jira/browse/FXU-50
LikeLike