Skip to content
Aug 2 2009 / alecmce

ASUnit Gotcha – Empty TestSuite Bug

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.

  • http://twitter.com/alecmce alecmce

    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

  • http://asunit.org/ Luke Bayes

    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

  • http://asunit.org Luke Bayes

    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

  • http://robertpenner.com/ Robert Penner

    I ran into this bug recently as well. Thanks for the fix!

  • http://robertpenner.com Robert Penner

    I ran into this bug recently as well. Thanks for the fix!

  • Anonymous

    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)

  • http://blog.vizio360.co.uk simone

    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)

  • http://alecmce.com Anonymous

    Thanks Simone, nice solution, I thought I’d tried that but clearly not…

  • http://alecmce.com alec

    Thanks Simone, nice solution, I thought I’d tried that but clearly not…

  • http://www.escortsmeet.com/ erotic services

    Drive Genius 3 is a suite of tools that focus on perhaps the most volatile of PC components, the storage drive. Whether an internal boot drive or external …

  • http://www.adhost.dk/sogemaskineoptimering.shtml søgemaskineoptimering

    Hardy and his friends would spend X-block mornings in the media center playing games until people started messing things up. “Kids I knew from middle school would come through and knock all the cards off the table onto the floor, just to mess up the …

  • http://www.eusuperpharmacy.com/ Kamagra next day delivery

    “The only problem is, after getting our coffee here for the past year, … the resulting empty burlap coffee sacks are available at $7.50 each. …