FlexMonkey is a new tool to perform automated testing on your Flex applications. With it, you can record a set of interactions, save those commands into a TestCase class, add the TestCase to your TestSuite, and include it as part of a FlexUnit testing workflow.
Unit Testing and Test Driven Development is an encouraged agile method for reducing bugs. Up until now though, Unit Testing has been restricted to testing everything but the User Interface. Sure, we can easily test our functions, utility classes, etc. but the real challenge for the Flash/Flex community has been how to test actual interactivity. I believe that FlexMonkey is on its way to solving this. FlexMonkey incorporates the popular FlexUnit testing framework. Here are some good tutorials to learn more about FlexUnit: Adobe Flex Cookbook
The big question to ask yourself is if you're ready to change your work flow and start writing tests first. Those who practice and advocate TDD (FYI, I'm still learning) will tell you that it changes the way you approach writing code. By writing tests first, it forces you to determine necessary functionality upfront. Cleaner code leads to less bugs. The other huge benefit is that functionality is constantly being tested. If a new feature breaks existing functionality, you will be notified immediately rather than it going undetected until a user finds it.
Steps to set up FlexMonkey.
There are really very few steps to get FlexMonkey up and running.
- Download the latest swc, at the time of writing this its in version .5:
http://code.google.com/p/flexmonkey/ - Copy the FlexMonkeyUI.swc into your projects lib directory.
- Write your first TestCase class. I'm calling mine BaseTestCase and storing it in a test package.
- Add your compiler arguments. These are going to be unique to your system. You'll need to know where your Flex sdk folder is located in order to include the automation swcs. You'll also need to point to your FlexMonkeyUI.swc. The reason for these absolute references is because FlexMonkey does a Mixin to reference the BaseTestCase.
-includes tests.BaseTestCase -include-libraries "/Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/libs/automation_agent.swc" "/Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/libs/automation.swc" "/Users/seth/Flex/tutorials/projects/flexMonkey/libs/FlexMonkeyUI.swc" - Write your first test and run!
Click here to see an example (right-click on the example to download the code):
http://9mmedia.com/examples/flexmonkey/
To make FlexMonkey run, click the FlexUnit Runner tab -> Run.
There are circumstances where you'll need to use these properties in your classes:
- automationName: I've used this when there has been a scope conflict - two components with the same id. Even though they live in different classes, the automation only recognizes them by their name. To fix it, I've added their uid to their id name.
- showInAutomationHierarchy: This has also helped with scope conflicts in a ViewStack.
Even though FlexMonkey is only at version .5, I'm already finding it to be a useful tool. When manually testing begins to feel like Groundhog day, its time to automate and make FlexMonkey work.
12 Comments