Wednesday, August 26, 2009

Wikipedia Is Still Free.

I have recently been sent an article by CNN about changes in Wikipedia. It decided to start to moderate the changes to articles about living people.

The article is interesting. Although, it's not much of a shift. There were some rules and monitoring in place already. Although, the results of these monitoring processes were only shown as warning/information boxes at the top of the articles. The change the article is talking about will affect only a small portion of the wikipedia articles. So, you're still free to go there and correct any misinformation, if any, about State of Oregon, US or City of Portland. Or extend them, if you know of facts that would be good to be there. It's still in your hands. Sorry, in our hands.

Go, ahead!

Tuesday, August 18, 2009

Using FlexUnit 4 with Flex 3: Sample Application

We had hard time finding on the internet a sample like this. So, here's ours. Additional steps required for this test to be run:
  • download FlexUnit 4 from their site.
  • add the FlexUnit swc files to the project's classpath
  • copy the sources below into your project and adapt them (use the view source icon in each source code frame below to view/copy the source code).
  • once everything is on place, right click on the TestRunner and select Run Flex Application.
At the end of the article, we have added some notes about using FlexUnit with FlashBuilder 4 and Flex 4
Enjoy! It's a great tool!

File structure

Tested Object

package olcc.account
public class Account
public function Account(){

private var balance:Number=0;

public function deposit(amount:Number): void {

public function withdraw(amount:Number): void {

public function getBalance():Number {
return balance;
Test Suite (Optional)

package olcc.account
import org.flexunit.runners.Suite;

public class MyTestSuite
public var t1: AccountTest;


Unit Test

package olcc.account
import org.flexunit.Assert;

public class AccountTest
public function testNew():void {
var account:Account = new Account();
Assert.assertEquals("Expecting zero account balance", 0, account.getBalance());

public function testDeposit():void {
var account:Account=new Account();
Assert.assertEquals("Balance on a new account after 50 deposit is 50",50,account.getBalance());
Assert.assertEquals("Balance after 50 deposit and another 25 deposit is 75", 75,account.getBalance());


public function testWithdraw():void {
var account:Account = new Account();
Assert.assertEquals("Balance should be: + $100 - $50 = $50",50,account.getBalance());

Test Runner
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=""

import org.flexunit.runner.FlexUnitCore;
import org.flexunit.flexui.TestRunnerBase;
//Add an import statement(s) for the class(es) under test
import olcc.account.MyTestSuite;

private var core: FlexUnitCore;

private function onCreationComplete():void
core = new FlexUnitCore();

<flexunit:TestRunnerBase id="testRunner" width="100%" height="100%" />

Using FlexUnit 4 with Flex 4

Flex 4 beta2 has support for FlexUnit, and the most recent version of it which is version 4.0. If you go to the New->TestCase menu, FlashBuilder can create for you a whole test class. And add to the flex build path the necessary libraries. This is done pretty well. But when I tried to apply the simple test application presented above to a Flex 4 application, I ran into multiple problems. One critical, as of today, was the issue that the AsDoc for Flex 4 is not available, nor much of the documentation for it. So, some classes from FlexUnit 4 that I needed (like TestRunnerBase), I wasn't able to find. Until these issues are resolved in Flex 4, I decided to use the FlexUnit 4 directly. To do this, I removed the Flex 4 libraries from the build path and added the FlexUnit 4 beta 2 libraries (.swc files). In general, the flex parser is not always stable, which showed up in this exercise and I had a compilation error that shows every other time I compile my TestRunner.mxml (with the same source code), but I can run the tests. Simply, I made sure that the last compilation is a clean one. Also, closing and reopening the project eliminated this issue.

Tuesday, August 11, 2009

FlexUnit Plugin for Eclipse

Since we intend to do unit testing in our Flex+Java development, I have been playing with FlexUnit and have found an eclipse plugin that makes it easier to use (also, in plugin central). Here's a summary and lessons learned on how to start with the plugin

Follow the installation instructions from here. Once installed, open the plugin's help in Eclipse and configure it. A few points:
  • Download FlexUnit and FlexUnit extension for the plugin.
  • You will need to have Flex Builder 3.
  • You will need a debugger version of Flash Player (I used version 10). A standalone player used by the plugin comes with Flex Builder (directory: player)
  • Follows instructions from Adobe on how to enable logging and error output for Flash Player. When you follow them, after you create a mm.cfg file, you will need to restart all instances of Flash Player for the Logs folder to show up.
Using The Plugin
To use a plugin:
  • Create a unit test using Flex Builder's wizard. I recommend keeping them in another source folder, so they can be easily skipped when releasing the app. For example, keep the flex source in flex-src and flex tests in flex-test. The server code put in java-src and java-test, or whatever language you use for the middle-tier.
  • Create a harness. Right click in the test file in the project navigator, find FlexUnit menu and select Create Harness. This will create a small mxml file for your test. However, if you use FlexUnit 0.9, the code needs a correction. Replace:
    EclipsePluginTestRunner.runTests( new Array(AccountTest.suite()) );
    with AccountTest.suite() );
  • Run the test. Right click on the harness file and select Run from the FlexUnit menu. Observer the test results on the nice eclipse viewer.
I had the problem that the test launch process never finishes in eclipse. But it doesn't seem to be harmful. Just ignore it.

It's a great plugin. It could do quite a bit more, but it's a great start. It worked for me with a FlexUnit 4, when I used the syntax of FlexUnit 0.9. When I switched to FlexUnit 4 syntax, I didn't have to apply the correction mentioned above to the auto-generated harness to compile. However, I didn't get my tests executed. So, I guess, for now, using the FlexUnit 0.9 is a better option. However, I have heard from the plugin author that he intends to do another release of the plugin.