My favorites | Sign in
Project Logo
                
Search
for
Updated Dec 30, 2007 by mccarroll.douglas
VisualFlexUnit  
Main documentation page for Visual FlexUnit

Visual FlexUnit (VFU)

Contributors:

Introduction

Visual FlexUnit is an Allurent open source project. Its goal is to establish a framework for the testing of components' visual appearance by enhancing FlexUnit with additional features to support "visual assertions". In a nutshell, a visual assertion asserts that a component's appearance is identical to a stored baseline image file.

For the present VFU should be considered an experiment in progress. While it's now reaching the point where it appears to be on its way to being a practical and useful tool, it's still in a very early stage of development. Simply stated, we don't have enough experience working with it to know where tweaks will be required. So, if your visual tests fail when you think they should be passing, this may simply be an indication that VFU needs to be tweaked. Please file an issue if you think that this may be the case.

If any of the explanations or instructions on this page are less than clear we'd be grateful for your feedback.

Overview

Visual FlexUnit allows you to write "visual tests" for your Adobe Flex projects.

In these tests you can:

Tests succeed if components and baselines are close enough to identical to be visually indistinguishable.

Tests can be run either in GUI mode or through Ant.

GUI Mode

The GUI version of VFU can run as AIR app or in Flash Player.

GUI mode will report errors, just like FlexUnit. It also allows you to:

Ant Mode

Why Is This Useful?

Regression Testing

By adding visual tests to your build process you can be assured that any changes to your codebase, or to the Flex/Flash framework, that effect the appearance of your components will be noticed immediately.

Testing For Cross-Platform Rendering Differences

While Adobe has done a great job of making Flash & Flex a write-once / deploy-anywhere platform, there may be differences in how images render:

To date our limited testing has only detected a) differences that aren't visually noticeable, and b) differences in very unusual cases that you would never use in the real world. Still, it doesn't hurt to check. By running regression tests on multiple platforms you can be assured that any unseemly differences in component rendering will be brought to your attention quickly.

How To Use Visual FlexUnit

Section Overview

The following subsections give directions on how to use Visual FlexUnit.

Introduction: Folder layout, naming conventions, example projects, etc.

Step 1: Bootstrapping a Visual Test Project: In this section we show you how to use an included Ant script to create an empty project framework for your visual test project.

Step 2: Writing Visual Tests: Writing test classes and methods for VFU.

Step 3: Running Your Tests with the VFU AIR GUI: How to run your visual tests in VFU's AIR GUI. This may be all you need to know. We think that VFU may be useful to many users who just use the AIR GUI to run tests, and skip the remaining steps.

Step 4: Connecting to VFU's Build Process: How to wire your newly created test project into the Ant build process that we've included with your download. This can be considered a continuation of Step 1 - the second half of bootstrapping a test project. We've placed it in Step 4 because some users won't want to go this far.

Step 5: Using the Build Process: Fifth, we explain how to use the build process to run your tests in automated mode in the Flash Player Step 6: Using VFU's SWF-Based GUI: See details below on why, if you've gotten this far, you might want to do this.

Introduction

Folder Layout

The downloadable visualflexunit.zip file unzips into this folder hierarchy:

  visualflexunit
    asdocs
    dev
      arc-flexunit2             - build process code
      flexunit                  - FlexUnit source code
      tools                     - build process code
      vfu
        vfuexample              - project containing example components
        vfuexampleTest          - example visual test project
        visualflexunit          - Visual FlexUnit source code
        visualflexunitTest      - unit tests for Visual FlexUnit code

These instructions assume that you'll be using a folder structure similar to that demonstrated by /vfu/ and its subfolders, i.e. that you'll have a parent project folder (/vfu/ in this case) which contains your 'tested project' and 'test project' folders. For example, if your parent project is named 'foo' and your tested project is name 'bar' you'd have:

   visualflexunit
     asdocs
     dev
       arc-flexunit2
       flexunit     
       foo
         bar
         barTest
       tools        
       vfu
         vfuexample 
         vfuexampleTest
         visualflexunit
         visualflexunitTest

Conventions

Example Projects

We've included two example projects in dev/vfu/:

Test Project Contents

Here's an overview of a VFU test project's contents. You can see this implemented in dev/vfu/vfuexampleTest/.

  dev
    [parent_project]
      [app_project]
      [app_project]Test
        .actionScriptProperties              \
        .flexProperties                       |
        .project                              |-- FlexBuilder project files & folder
        .settings                             |
          org.eclipse.core.resources.prefs   /
        build.xml                               - Ant build file
        build-imports.xml                       - ditto
        libs                                    - Folder included because FlexBuilder requires it - not used
        src
          VfuAirGui.mxml                     \
          VfuAirGui-app.xml                   |-- GUI app files
          VfuSwfGui.mxml                     /
          VfuGuiFlexUnitAllTests.as             - Lists test classes    
          baseline                              - Folder for image baseline files
          com                                   - An example of a source code folder that you might add
          skinning
            styles.css                          - Used by both GUI and automated test apps 
            fonts                               - Folder for font files

VFU will store baseline images in the project's src/baseline/ folder using a structure based on: a) test class names, b) test method names, and c) assertion IDs:

  dev
    [parent_project]
      [app_project]Test
        src
          baseline
            SomeTestClassName
              someTestMethodName
                1.png                      In this case, "1" and "2" are "assertion IDs". These are
                2.png                      passed in when visual assertions are made. Any integer ID 
              anotherTestMethodName        can be used but, obviously, they need to be unique within 
                1.png                      a given test method.
                2.png
            AnotherTestClassName
              etc...

Step 1: Bootstrapping a Visual Test Project

The Visual FlexUnit download includes Ant scripts that will allow you to bootstrap a test project for [app_project]. Bootstrapping includes:

Bootstrap How-To

Assumptions:

We make the following assumptions. If these are correct you should be able to bootstrap projects by following the directions below. If you have sufficient Flex and Ant knowledge you can work around these, e.g. compiling your AIR GUI test app from the command line, but we don't cover such scenarios here.

Steps:

Step 2: Writing Visual Tests

Before you start this process you'll need to decide which visual components you'd like to test. Your options include:

A. Create A New Test Class

Instead of subclassing TestCase (the standard FlexUnit approach) subclass com.allurent.flexunit2.vfu.framework.VfuTestCase.

Note that VfuTestCase extends TestCase so you can do all the things that you can normally do in FlexUnit test classes. The next section explains how to write visual test methods but you can also write standard FlexUnit test methods and assertions.

As usual, your test class's name should end with "Test".

B. Write Visual Test Methods

Let's start with an example:

testMyAccordionComponent():void
        {
            var comp:MyAccordionComponent = new MyAccordionComponent();
            with (testSequence)
            {
                addSetProperty(comp, "selectedIndex", 1);
                addRefresh();
                addAssertComponentMatchBaseline(comp, 1);

                addSetProperty(comp, "selectedIndex", 2);
                addEventDispatch(comp.getHeaderAt(0), new MouseEvent(MouseEvent.MOUSE_DOWN));
                addRefresh();
                addAssertComponentMatchBaseline(comp, 2);

                start();
            }
        }

As you can see, testSequence is central to VFU's test process. Here's a quick overview of what testSequence is and does:

Now that you have an overview, here are the details of how to write your own test methods:

As you can see, the example method:

Your visual test methods should follow the same pattern as the example. The action sequence in the second step will generally consist of one or more repetitions (the example has two) of this subsequence:

See the Visual FlexUnit ASDocs for com.allurent.flexunit2.vfu.framework.testsequence.TestSequenceManager for details on its add[some_command]() methods, their parameters, etc. ASDocs can be found in the /visualflexunit/asDocs/ folder in the visualflexunit.zip download file.

As usual, your test method names should start with "test".

C. Add your test class to VfuGuiFlexUnitAllTests.as

Open /[app_project]Test/test/flexunit2/VfuGuiFlexUnitAllTests.as and follow the instructions in the file.

You're now ready to run your tests!

Step 3: Running Your Tests with the VFU AIR GUI

Launching the AIR GUI

The Eclipse project that we created above is an AIR project. Right click your project in the Navigator view and select Run As | Adobe AIR Application or Debug As | Adobe AIR Application.

Viewing Results in the AIR GUI

As your tests run you'll see your components appearing and disappearing on the screen. When this stops you'll see a UI that is in some ways similar to FlexUnit's. The left hand panel has the Failures and All Tests tabs that you've come to know and love. If no failures are displayed, you're all set.

Failures for visual tests come in two varieties:

1. Missing Baseline Failures

These occur the first time you run a given visual assertion. Confirm that the displayed image meets your expectations, then click the button that says "Yes, Use The Current Bitmap As A New Baseline". If the image displayed doesn't meet your expectations this is probably due to issues unrelated to VFU. On the other hand, if your component's image is different in VFU than it is in other settings this may be something that we need to look at so please file an issue.

Note that VFU will only report one failure of this type for a given test method each time you run it. In other words, if you write a test method with four visual assertions, you'll have to run the AIR GUI version of VFU four times in order to create the requisite four baseline files. We suggest that you develop a habit of running the GUI immediately after you write each assertion in order to avoid confusion.

2. Bitmap Doesn't Match Baseline Failures

When these occur your best first step is probably to click the Open Diff Viewer button. This will display both images, alternating, so that you can easily see how they differ.

Step 4: Connecting to VFU's Build Process

Visual FlexUnit's Build Process

This section outlines a series of steps that you can take to connect your visual test project to the Ant-based build process that we include as part of the VFU download. We don't attempt here to explain how the build process works as that's outside of the scope of this project, but if you're interested in learning more, here are some resources:

Conventions

We'll continue to use our previously defined conventions here, i.e. we use [app_project] to represent your tested project's name, and [parent_project] to represent the intermediate folder between dev/ and your project's folder.

(For the purposes of these instructions [app_project] simply indicates your tested project's folder's name. If you choose to also implement the build process modeled here for your tested project you'll also use this name for your Ant project's name attribute, but we digress.)

4.1 Setting User-Specific Settings

4.2 Wiring The Tested Project's SWC Into The Process

4.2.1 [app_project]'s build-assets.xml

This file informs the build process of the location of [app_project]'s SWC.

4.2.2 Parent Folders' build-assets.xml Files

These files wire [app_project]'s build-assets.xml file into the build process.

4.3 The Test Project's Build Files

The bootstrap process (Step 1) created build.xml and build-imports.xml files in dev/[parent_project]/[app_project]Test/. These are complete and ready to use.

4.4 [app_project]'s Build Files

Optional. If you'd like to include [app_project] in the build process, follow these steps:

4.5 Pulling The Process Into The Test Project

4.5.1 dev/[parent_project]/build-imports.xml
4.5.2 dev/[parent_project]/build.xml

Optional. If desired, you can create a build file for the parent project that will build both [app_project] and its test project, then run the test project's tests. To do this:

4.5.3 dev/build.xml

Optional. The dev/build.xml file does the same thing as dev/[parent_project]/build.xml, but for the entire build process. If you'd like [parent_project] to be included when we tell the build process "build and test everything" follow these steps:

Step 5: Using the Build Process

Prerequisites

We assume that you have done the following:

Automated Mode In Flash Player

At the command prompt:

(If you're testing the example test components that we provide in vfuexample you'll find that there is one test that reliably fails at this point. The testCanvas_2() test method tests a component that consists of buttons on a canvas. We've specified drop shadows for the buttons, using bizarre property settings for the shadows. One of these buttons renders differently across the AIR/SWF divide. We suggest that you re-run the tests in the SWF GUI, as explained below, and take a look with the diff viewer.)

More Work For Extra Credit :)

In an ideal world you'll be running a one click automated build process that builds and tests all of your projects. We've included a working build process for the entire dev/ folder in the VFU download. The steps needed to wire both [app_project] and [app_project]Test into this process have been listed in Step 4. Also, the framework for including sub-projects is modeled in the dev/vfu/ folder.

Your mission, should you choose to accept it, is to wire your projects into the process. To test the process:

Good luck!

If Tests Fail In Automated Mode

If any of your tests fail you will probably want to run them in GUI mode in order to see how your test results differ from the saved baseline images.

If you've run your tests on a different platform from that in which their baseline files were created (e.g. you created baselines in AIR, then ran the tests in the Flash Player, and they failed) you should obviously run the same test-platform-type of GUI (e.g. in the example just cited, run the SWF GUI) to view the differences. Running the GUI in the platform in which the baseline files were created will probably simply result in your tests passing, which won't tell you much.

Step 6: Using VFU's SWF-Based GUI


Sign in to add a comment
Hosted by Google Code