views:

909

answers:

3

I build and maintain a set of Flash components that is distributed to publishers and allows them to integrate with our system. Currently the component has no UI and simply contains compiled code for querying our system servers, parsing the response, and modifying the params sent in the query. There's an As2 version and AS3 versions for both Flex and CS3. Our typical workflow is like this:

1.) load the component 2.) set parameters on the component 3.) tell the component to query our system 4.) wait for an event saying the response has been received and parsed 5.) call methods on the component for retrieving and using parsed data

We've been talking a lot lately about automating the testing of these components, and there seems to be a lot of buzz around frameworks like AsUnit and FlexUnit. However, I've never been able to grasp how I might effectively use of one of these. The examples and tutorials always skimp on real-world examples and instead provide multiple classes and excessive code for testing whether an example function returns num1+num2.

The only thing I can guess is that these testing frameworks are intended to be implemented from the start, with planning for the test suite, test runner, and test cases built in at the start of development.

An automated test of our component would have to make sure properties were properly set, those properties were sent in the request to our system, the response received was correct considering the parameters sent, the parsed data includes correct information, and no errors, bad responses, or infinite parsing loops are caused.

my question is, is there any way to automate testing of an existing, widely distributed, established Flash component without completely reworking it to fit into a testing framework? Or am I misunderstanding the test frameworks and this is already possible?

UPDATE: Thanks for the responses. I have started to integrate my component with AsUnit and think I have a pretty good understanding of how it can help me. However, the AS2 AsUnit does not support asynchronous test cases, and I'm having a hard time finding an AS2 unit test framework that does. Asynchronous testing is REALLY important to this project. Does anyone have any recommendations for a different framework? Thanks!

+3  A: 

We're using FlexUnit on our project and I'm pretty happy with it. Assuming your project was designed with a fairly loose degree of coupling, you shouldn't need to change much at all (if anything) in order to test your code. If you're already using an MVC framework like Cairngorm or PureMVC, FlexUnit should integrate pretty painlessly.

I will say however that my experience with Flash/Flex unit testing is not nearly as positive as it has been with other languages such as Ruby or .NET for three reasons. First being that such a high degree of actionscript code is UI related, and this sort of code is difficult if not impossible to test. Another reason is that the test runner doesn't lend itself well to being plugged into a continuous integration environment such as CruiseControl.NET or CruiseControl.rb since it requires a human to run it and click buttons. Lastly, a huge benefit of unit testing is usually that you can run it alongside a coverage analysis tool such as NCover or rcov. Flash/Flex doesn't lend itself to this sort of analysis with out a modified compiler such as Flexcover.

rboyd
+1  A: 

While I never had the chance to work with a unit tester in actionscript, at work we created a framework which:

  1. compiled the script(s) inside a test application, in our case with flex
  2. set up a timer (watchdog) application, in case of loop failure
  3. ran the application which, in turn:
    • connected to a PHP backend to get a test case
    • fed the test to the component
    • read the results and sent them back
  4. the watchdog would kick in and kill the application on whichever happened first:
    • timer ran out (reasonable timeout)
    • application sent back the results
  5. if there were other tests to run, goto 2.

Definitely not elegant, but did the job (this was with AS1 scripts)

ptor
+1  A: 

Glad to hear you went with AsUnit!

AsUnit is the only unit test framework that will give you a consistent experience in ActionScript 2 and ActionScript 3. It has no dependency on any external frameworks - especially Flex, and there should be no real issues with creating tests for your project after the fact.

The latest builds of AsUnit do have support for asynchronous testing in ActionScript 2. The as25 branch can be found here:

http://github.com/lukebayes/asunit

Luke Bayes
thanks Luke! I'll have to take another look at this then!
nerdabilly