AlecMcE.com

Coding on the Flash Platform

ASUnit Gotcha – Empty TestSuite Bug

View Comments

This afternoon I discovered an interesting little bug in the ASUnit library which causes the TestRunner never to finish its suite of unit tests. It is fairly straightforward to reproduce too: simply, add create a TestSuite that doesn’t contain any tests and add the suite to the runner.

Though I have created an artificial example to isolate the problem, it arose in a real-world situation. I had two package folders in which I intended to create tests. I created all the AllTest TestSuites but only populated one of the packages with tests. When I tried to run the TestRunner to see the results of these tests, though they appeared to have run the TestRunner had never completed.

The source of the problem lies in the architecture of the TestSuite class, the main functionality for which is launched by the run method but which dispatches an event to indicate that it has finished performing tests in its testCompleteHandler method. However, testCompleteHandler can only ever be triggered as a consequence of a test completing in run, so if no tests are defined, the TestSuite never finishes.

Update

I posted my resolution of this problem on github, but it has since been merged to the asunit trunk, so I have removed the github repository. My solution added checks for empty TestCases and TestSuites to prevent the TestRunner trying to run them.

Written by alec

August 2nd, 2009 at 11:21 pm

  • Thanks Simone, nice solution, I thought I'd tried that but clearly not...
  • another fix could be to check the number of tests in the testSuite and if it's 0 just send a COMPLETE event.

    so in the run method of the TestSuite add the following lines just before the "while(itr.hasNext())"

    if (testCount() == 0)
    {
    dispatchEvent(new Event(Event.COMPLETE));
    return;
    }

    if you run an empty TestSuite with this fix you'll get:
    OK (0 tests)
  • I ran into this bug recently as well. Thanks for the fix!
  • Hey Alex,

    Thanks so much for bringing this up and even more for submitting the patch!

    Your fix has been pulled into trunk and released at http://asunit.org
  • I’m actually grateful for the terrible commentary from avfc.co.uk on the Villa while I worked on an bug in #asunit, http://bit.ly/sSF1S.


    This comment was originally posted on Twitter

blog comments powered by Disqus