Thursday, July 17, 2008

Modular Test Driven Development

So as I mentioned before we've decided to use FlexUnit to do test driven development in Flex for our latest project. We also want to do modular development in order to support Bundles as per the OSGi framework which I also mentioned before. In order to make these two things work together easily I wanted to be able to simply drop modules into a 'test runner' flex application and have it run all of the tests embedded within that module. Zach Smith, one of our new developers, whipped up a pretty nice test framework and test runner application which allows us to do just that.

For the test framework he extended the Flex Module class to make a TestModule class. All of the tests within your module are then registered with your TestModule. Below is an example registering a TemperatureConverterTest.

example_testmodule

You'll notice the line 'this.testClassArray' which is the inherited property from the TestModule class. After that you drop the swf from your built module into the directory containing the test runner application, edit an xml file to register your module with the test runner, and run the application. The application is the basic FlexUnit built in interface.

I'm really pleased with the way this turned out and it's going to make unit testing fairly easy since we can do it all in one central location, and since it's a Flex application we can leave it on a central server and run it from anywhere within our internal network.

No comments: