10 Questions About FlexUnit and Cairngorm
Since I have been struggling with FlexUnit in my "free time" over the past few weeks I was anticipating Wednesday night's AFFUG meeting featuring John Mason presenting Unit Testing and Test Driven Development (TDD) for Flex & ActionScript 3.0. John gave us a good overview of where unit testing came from and how it is applied to Flex and Actionscript. He also showed an example application that worked, created a couple of tests for it which promptly failed and then fixed the code.
[Leif's Note: If you want to skip the introduction to this entry, feel free to skip down to "1. Who is using FlexUnit?"]
What is FlexUnit, Anyway?
FlexUnit, which is based upon JUnit, is a framework that allows for unit testing with Flex applications. Wikipedia says that unit testing is "a procedure used to validate that individual units of source code are working properly." Ideally, a developer would create a unit test that tests a feature before beginning to program the feature. This process empowers the developer to fully understand the feature they have been assigned to create and to plan for all the potential problems that could occur with the feature. The end result is that the project would have a unit test to verify the feature is working and that all the unit tests could be run every time a build is created to verify that all features work. Unit testing is a fundamental part of test-driven development and continuous integration, concepts that I will not be discussing today but needed to mention.
So, What is Your Beef with FlexUnit?
The way John Mason presented it, FlexUnit seems very cut-and-dried simple until you consider two things: 1) Actionscript is/can be asynchronous and 2) we use the Cairngorm framework at Roundbox Global when we create applications in Flex. Also consider that it is likely that these two factors would be considered too advanced to be covered at any user group meeting that I could attend, may be too complex for a 55 minute session at MAX, and not many people are even talking about FlexUnit much less Cairngorm. Is there some vast conspiracy to keep this kind of information away from me?
Why is FlexUnit so Important?
FlexUnit is important because rich Internet applications (RIA) are complex. As a developer, I believe that it is my responsibility whenever possible to make certain that my code works well — not only should functions meet their requirements, but I should investigate that feature so that my code has as few bugs as possible, and that my code does not break other parts of the application. With the complexity of a modern RIA and the the larger teams needed to create these applications, this ideal is difficult to achieve. Developers need to utilize any tools available to reduce the stress of quality assurance (QA) departments (as well as the stress between development departments and QA departments) by eliminating defects in development. Unit testing is one of those tools.
With the size of the applications being built and the teams required to build them today, no company can afford to have seemingly endless cycles of our QA department finding things that developers should have thought of or found before committing their code. Developers must take responsibility for their work! They can not give excuses like "it wasn't in the wireframes", "I didn't think about that", "it's not my fault my code broke their code", or the classic "it works great on my machine" without impacting harshly on the whole team's deliverables, deadlines and work schedules. Ultimately, we all want to have a 40 hour work week.
What we are trying to do at Roundbox Global is establish a best practice of creating unit tests to establish a build's viability before handing the build off to QA for testing. Passing these unit tests should reduce the chance of QA receiving a build that, after hours of testing, is found to be invalid because of some flaw. We are also hoping to add some automated testing to our process in the near future as well.
So here are my questions to anyone who wishes to answer. Yes, there are more than ten questions. Consider them as ten groups of questions. Jump into the comments to let me know any facts or opinions that may help me and any readers out there. Hopefully I will be able to update this post with more details before the end of the month.
1. Who is using FlexUnit?
At Wednesday's event I got the impression that there were not that many developers already using FlexUnit. Are developers out in the wild using FlexUnit? Or are developers not doing any unit testing at all for Flex projects? I've heard that the folks at Universal Mind are using FlexUnit. Who else? And are they using FlexUnit with their over-all unit testing plan or just with Flex? And are they using continuous integration?
2. Who is Using FlexUnit with Cairngorm?
John asked the audience at Wednesday's event if they used the Cairngorm framework. Only a tiny minority raised their hands. You may already know how I feel about Cairngorm — it blows my mind when I hear about large projects that were not created using the Cairngorm framework. So, if a minority of people use Cairngorm and a minority of Cairngorm users use FlexUnit, where does that leave us? Considering that sites like FlexExamples have one or two entries daily, I'd call it a communication void.
3. Must I Change FlexUnit to Use Cairngorm with FlexUnit?
In my searches for FlexUnit information online I ran into several blog posts about using FlexUnit and Cairngorm. Each of the entries seem sincere, although somewhat incomplete, these post seem to say one thing: FlexUnit is not ready for Cairngorm. Must we make changes to the FlexUnit to get the asynchronous functionality necessary with Actionscript and Cairngorm? Could there be a good way to get the changes needed committed to the repository? Or are there issues with adding these modifications to FlexUnit?
4. Where are the example applications (using Cairngorm or not)?
Using FlexUnit is probably "no big duh" to a seasoned Java developer. But as John showed us Wednesday night, FlexUnit makes a lot of assumptions of users. For instance, did you know that test method names need to start with the word "test"? It's not just a naming convention, as we were shown last night, it's a requirement. So, for those of us who aren't seasoned Java developers with years of unit testing experience, where the heck are our FlexUnit examples? It would be nice to have some easy and complex examples of unit testing applied to something like the Flex Store (or the Flex Cairngorm Store, or the Flex Cairngorm ColdFusion Store). I'd do it myself (and may yet) but I am still getting my head around using FlexUnit.
Leif's note: I posted a few locations of FlexUnit examples in another blog post here.
5. What do we test with FlexUnit?
So what exactly do developers test with FlexUnit? I believe that we can completely test our connections to the back-end fairly well with FlexUnit — we can test that proper data is returned from the server using different types of data. But, without getting into an automated testing discussion, isn't there something more we can test? For instance, with Cairngorm, we can test Delegates. But shouldn't we take it a step further and test the Event, Command, and Delegate sequence? (I like to call that the ECD chain, by the way) Sure, making certain that the Delegate is working is important, but if you are using Cairngorm correctly you would never call a Delegate without invoking an entire ECD chain. And are developers testing for results of Delegates, or are they testing
6. What is the best way to use setUp and tearDown with Cairngorm?
As you may know, it is common best practice to use the setUp and tearDown methods for every test. When I use Cairngorm and I want to test a specific Delegate or ECD chain, often there are items that need to be set in the model for the Command to call the Delegate properly. Would it be all right for me to directly set things in my ModelLocator, i.e. without using an Event like these items would normally be set in the application? Same question goes for the tearDown.
7. What else are other developers using with FlexUnit?
Are there other "gotcha's" with FlexUnit that I don't know about? Seriously, no one is talking much about FlexUnit and the docs are minimal. Are developers modifying FlexUnit to work around problems or bugs? Are developers successfully using FlexUnit with Cruise Control?
8. Why is FlexUnit stuck at version .85?
Besides the changes to allow for the use of the Cairngorm framework, what functionality is missing from FlexUnit that has it stuck on version .85? What kind of effort will it take to get FlexUnit to a rock-solid 1.0 version? I realize that most of the owners of FlexUnit are either busy working on Flex 3, AIR or consulting for Adobe. But since I do not see a road map, I have no idea what is missing and how developers may assist them to reach this necessary goal. And while we are at it, when the heck is Cairngorm going to get the same open source treatment as FlexUnit? I love what you did to simplify Cairngorm in version 2.2!
9. What is next for FlexUnit?
Could there be more modifications necessary in FlexUnit to make it more compatible with the asynchronous nature of Actionscript? Are there new features in JUnit that need to be added to FlexUnit? Again, what is our roadmap?
10. Does Flex 3 take advantage of FlexUnit or Cairngorm?
With the upcoming release of Flex 3, will there be any new features around creating projects using Cairngorm or creating unit tests with FlexUnit? Flex Builder Wizards like Cairngen? Wouldn't it be great to point a Flex Builder Wizard at a folder of Delegates and have simple unit tests created for you? Mmmmm, goodness.
3421 Views



Comments
Anyway, I ramble. Adobe's at a point where they can really turn the curve and make it a platform for developing big things, but Microsoft is going to be hot on their heals, with their nearly unlimited resources, to make Silverlight the developer platform in a couple of years.
And why do I bring all this up? Because I want to go to the Adobe sight for best practices on building large apps, and I find none. I find a Cairngorm page, with links that start you on a mission all over the blogshpere to find how to implement things. And this reminds me all of the FlexUnit and Cairngorm issues because if Cairngorm is such a great way to code a large application, why is it so hard to find best practice links, solution FAQs, additional patterns references, unittesting, etc...at the Adobe site? Instead, I must rely on my superior ability at using Google to piece together a cohesive picture. Then again, I guess this is why companies pay me to come architect their applications.
It really seems that Adobe could leverage their consulting solutions team a bit more and share a lot more of what goes on at their big deliverables and share a lot more of their boiler-plate code, like Microsoft does with their Enterprise Patterns stuff...
I hope you'll continue to post about your findings to the questions you ask! I'll be sure to keep reading them.
Now that ASUnit has been mentioned and seems to support the async nature of Flex, I will start to look into it.
Very informative post. Thanks for addressing this often overlooked development best-practices: Unit Testing.
have seen the tests directly invoking the delegate. Instead How can I start from event to have a full flow of ECD (Event-Command-Delegate-- result() Command---
Using Flex Unit It should be able to have this flow. Suite - Test - Event- command - delegate - result() of Test [Not result() of command ]
Earliest response is really appreciated.
(I'm using Flex uUit in my project and just testing the delegate connectivity. I've found the need to test whether you've hooked up your command and event properly a little unnecessary, especially if you're creating your events, commands, with code generation.)
I'm watching the DPUnit project closely, since they seem way ahead of everything else on unit testing Cairngorm