I\'m trying to improve my code by writing unit tests for my ActionScript 3 code for Flash projects I work on, but I\'m having a mental hurdle understanding how to deal with it i
I like abstracting application logic from front-end display stuff. I don't believe it is very useful to unit-test front-end/display stuff, but you can unit test the internal logic and functionality of the system. It's the MVC design pattern.
For example: Suppose you have a Flash game where there is a player that can attack enemies. You might have a class Player
, a class Monster
, and a method Player.attack(monster:Monster)
.
Your unit tests will set values in a Player
and Monster
, and call attack()
and then make sure the results are correct.
Your front-end display, the stage, clickable objects, etc. and UI will also make calls to these objects when appropriate in a live environment.
The unit tests would run in a separate .swf file which executes tests that import the model objects (Player
, Monster
, and whatever else you might have), but completely ignore all your visual/display elements. I would avoid unit testing anything that involves user interaction.