Chapter 10. Testing your Flex application

 

This chapter covers

  • Unit testing with FlexUnit
  • Mock testing with mock-as3
  • Leveraging the hamcrest-as3 matchers
  • Generating a test report

Every good programming book includes a discussion of unit testing. Whether you follow the practice of test-driven development, which the authors advocate, or write your tests after the fact, an automated suite of unit tests is a valuable accompaniment to your application. A comprehensive suite of unit tests proves to your customer that the code you wrote does what it’s supposed to do. It also provides developers making changes to your code both confidence that the changes will not break anything and up-to-date documentation in the form of unit tests. Written documentation can easily get out of sync with the implemented code; a good suite of passing unit tests should always be in sync with the code. You can think of your unit tests as a form of executable documentation that developers can use in the years to come.

10.1. Unit testing and TDD

If you’re not familiar with the practice of Test Driven Development (TDD), figure 10.1 shows the basic workflow. In a nutshell, you start by writing a failing unit test, then write only enough implementation code to make it pass. When you get a passing test, you start the process over again.

Figure 10.1. TDD workflow

10.2. Updating the project

10.3. Testing the Presenter

10.4. Testing the View

10.5. Testing the Model

10.6. Continuous integration with Hudson

10.7. Summary