Details

Version 0.2.0
Last updated 12th March 2008
Requirements
Demo View demo page
License BSD License
Changelog
0.2.0
  • Fixed: Issue where error thrown when no test results selected.
  • Fixed: Issue where resizing columns could cause the itemRenderer for the status to display horizontal scrollbar.
  • Added: Ability to choose whether to display test results live or wait until all tests complete (as displaying them live results in slower execution of tests, as it's constantly updating the UI) - this is saved as a preference.
  • Added: Ability to toggle display of the class path for the test case - this is saved as a preference.
  • Added: Test result details now extract Expected & Was from message string for failures and display in a manner that is easier to compare.
  • Changed: Test details now displayed on change rather than click event, to allow keyboard navigation of test results.
0.1.0
  • Initial verison

About

The FlexUnit Custom Test Runner is a customised FlexUnit test runner which aims to improve the presentation and ease of use of running FlexUnit tests.

I have used unit testing in a few different languages, so obviously when I started using Flex I wanted to start off on the right foot by using unit testing from the outset. However after a couple of days using the base runner which is provided with FlexUnit I found myself spending a lot more time than I thought I should just looking for the details of the problem in the flex runner.

I think that the base runner is not conducive to quickly finding the cause of test failure(s), I believe it is due to the following reasons:

  1. The test failure/error message is not presented against the failed test.
  2. Trying to read the stack trace is made difficult due to it being in a narrow column (lots of scrolling is required, especially when testing deep component packages).

Features

Screen shot of FlexUnit Runner in action

  • All features of standard base runner.
  • Uses DataGrid to present test results, allowing clearer overview of tests that have been run & their status, plus ordering by test cases etc.
  • Filter results by different types, all, failures, errors.
  • Instant feedback on test status through use of icons.
  • Instant feedback on reason for failure/error with FlexUnit failure message included inline with the test results.
  • UI gives more room for stack trace, making it easier to read.
  • Only displays stack trace when selected a test.
  • Stack trace highlights lines (in bold) that relate to your test case, helping you quickly zone in on the issue within the stack trace.
  • Added experimental timing of the tests in the results.

Features added in 0.2.0

  • 2 downloads are now available, one compiled to Flex 2.0.1 and the other compiled to Flex 3 as internal changes to Flex mean that the Flex 2.0.1 swc didn't work in Flex 3 projects.
  • Ability to choose whether to display test results live or wait until all tests complete (as displaying them live results in slower execution of tests, as it's constantly updating the UI).
  • Ability to toggle display of the class path for the test case.
  • Test result details now extract Expected & Was from message string for failures and display in a manner that is easier to compare.
  • Preferences (display class path, live results) saved automatically to a shared object.

Usage

Once the FlexUnitRunner.swc is added to your library path for the Flex compiler usage is as simple as replacing any instances of the <flexunit:TestRunnerBase .../> component in your test runners.

Example:

MXML:
  1. <mx:Application
  2.         ...
  3.         xmlns:defusion="http://www.defusion.org.uk/mxml"
  4.         ... />
  5.        
  6.         <mx:Script>
  7.             <![CDATA[
  8.                 // usual flex unit code to load test cases
  9.             ]]>
  10.         </mx:Script>
  11.        
  12.         <defusion:FlexUnitRunner id="testRunner" width="100%"
  13.             height="100%" />
  14.     </mx:Application>

Demo

There is a demo for the FlexUnit Runner which has a test case which has tests that produce the different scenarios found in FlexUnit tests: success, failure, error, to provide an example of how the FlexUnit Runner handles these scenarios.

A note on the test timing

I have added some timing around the running of each of the tests within the runner, these times are then displayed in the results.

I've had a poke around the source code for FlexUnit but find it quite difficult to follow through running a TestCase (as it bounces around all over the place within the code - thankfully I'm not the only person to have problems trying to follow the code). So I'm not 100% sure on the accuracy of the timing I am attempting. For example, I'm not sure if the code I'm testing includes the calls to the setUp and tearDown methods - which if it does these will be included in the timing.

Next Steps

Leave a Tip

If you find this code useful you can leave a donation towards the continued development & support.

Comments

There have been 11 comments so far, join the discussion.

1. Robert Stehwien - 18th Oct 2007 - 6:00 pm

Nice, I’ll give it a try shortly (have an urgent bug to fix first). The demo page doesn’t work (in IE or Firefox) and a larger image of the thumbnail would be nice.

Thanks!

2. Dave - 19th Oct 2007 - 9:22 am

Robert:
Thanks for the heads up on the issues. I’ve linked a larger version of the screenshot to the thumbnail and updated the demo, although I wasn’t having a problem in either IE or Firefox I removed some JavaScript that was resizing the i-frame as I suspect that was the problem.

3. VICTOR - 20th Oct 2007 - 6:16 pm

hello Robert, how are you?
My name’s Victor and I’m 18 years old, I’m from Brazil.
could you answer me if is there any way for integrate the flexunit with maven?

I’m working in a flex+java project and trying to make the tests with the actionscript files like we can do with the Java classes: just typing “maven test”(or “maven clean install”- for the build process) and wait for the result.

I saw this link http://www.servebox.com/foundry/doku.php?id=m2f2plugin
but i don’t want to see the window test in the browser (as we don’t see the UI of Junit in the “maven test”).
thankyou very much, bye

4. Robert Stehwien - 20th Oct 2007 - 6:38 pm

Dave,

The UI looks nice. I hooked it up to the excel like expression parser I made in Flex to see how well it performs time wise (well I might add), and the UI looks vastly superior to the existing one. I’ll post this to the user group too.

Victor,

I don’t use maven (actually I’m trying to decide what continuous integration and build tools to use in our dev process). I saw the same link you did plus this blog about using the maven-ant plugin to run unit tests:
http://maximporges.blogspot.com/2007/09/maven-2-property-references.html

I’m probably going with ANT for builds since that is what Adobe and antenna use:
http://code.google.com/p/antennae/

In my heart I yearn for rake though, but the company I work for uses .NET for the middleware and not rails.

Also try the flexcoders group, I’ve seen some discussion there on maven:
http://groups.yahoo.com/group/flexcoders/
—Robert

5. Adam - 21st Oct 2007 - 10:24 pm

Thanks, my first try with this component was unsuccessful until I added a check for null:

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

super.updateDisplayList(unscaledWidth, unscaledHeight);
if (this.data == null) return; //This line added by Adam

Now it works like a charm! Thanks. Perhaps its was a timing issue. Is there data for the item renderer when the test is starting?

6. Robert Stehwien - 23rd Oct 2007 - 6:11 pm

There is an assertion if you follow the following steps:
1) Run your tests
2) Click on the header of the table to sort by Status (actually anything works)

Shows an ActionScript error for accessing a null object in showTestDetails()

If you click on a test row first so the details are showing, then sorting on the column header doesn’t cause an error.

7. victor - 29th Oct 2007 - 1:23 pm

thankyou very much for your answer Robert.
I got runnig maven + ant task.
now I’m trying to remove ant from the pom.xml
if I get and I’ll post here how to.
good bye

8. dimitri@forms.ge - 30th Apr 2008 - 8:43 am

I cannot run asynchronous test using your UI, while on FlexUnit they run correctly. The problem is, after call to addAsync and compliting the test, all other tests are waiting and never start.

9. dimitri - 30th Apr 2008 - 8:47 am

Now it works (when I removed custom style).

10. Dave - 30th Apr 2008 - 9:04 am

Dimitri:
I currently don’t have any async tests, in your second comment do you mean you’ve fixed the custom runner or removed it? If you’ve managed to fix the runner I would gladly add the fix to the release.

11. Tyler Patterson - 19th Jun 2008 - 12:55 am

Looks sharp! Way better then the one that comes with FlexUnit. I also like that it displays the timing.

Thanks!

Leave a comment

No HTML please, only textile. For code please use [lang]...[/lang] tags (e.g. [html]...[/html] for HTML)