Chapter 73. Unit Testing and Test-Driven Development with FlexUnit

This chapter covers the practice of unit testing and the best practice of Test-Driven Development (TDD), using FlexUnit, the open-source unit-testing framework for Flex. When practiced together, these techniques are invaluable, helping you to write more robust and better designed software with fewer dependencies and looser coupling between classes. You can catch bugs early, before they can enter production, when the cost of fixing them is much higher.

Overview

Unit testing is the practice of testing the small pieces of functionality that make up an application to ensure that they operate correctly. These small pieces are the units, and they are tested to ensure that each one satisfies its contract by returning the expected results, handling errors appropriately, and collaborating properly with dependent interfaces. If each unit of a system is deemed to be correct, one might infer that the system as a whole is correct. In reality, such a claim would be presumptuous, but unit testing does provide many benefits and reassurances.

TDD is a technique that takes unit testing to its logical extreme, by advocating that unit tests be written first, before the functionality that will actually be tested has even been implemented. Unsurprisingly, the unit test will initially fail, since the functionality has not been written, but when it does succeed, the developer knows that the code is correct. This process can seem back-to-front ...

Get Professional Adobe® Flex® 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.