Unit Testing AS3 Code for Flash

前端 未结 2 860
终归单人心
终归单人心 2021-02-05 09:29

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

2条回答
  •  醉酒成梦
    2021-02-05 09:48

    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.

提交回复
热议问题