Scott,
I'm looking into the problem we discussed with GWTTestCase exceptions, and I
think I have all the cases characterized now.

--- for the edidification of gwt-contrib ---
I'm writing some code to allow you to trigger events (a la
createEvent()/dispatchEvent()), primarily for testing purposes, and ran into
a problem testing them with GWTTestCase. If you write a test like the
following:

  public void testTriggerScrollEvent() {

    init();


    NonBubbleAssertingEventListener listener =
newNonBubbleAssertingEventListener(

        "scroll") {

      public void onBrowserEvent(Event event) {

        super.onBrowserEvent(event);

        assertEquals("scroll", event.getType());

      }

    };

    Event.setEventListener(parent, listener);

    Event.setEventListener(child, listener);


    Event.triggerScrollEvent(child);


    assertTrue("Expected child to receive event", listener.childReceived);

  }

... and the assertEquals("scroll", event.getType()) fails, GWTTestCase
catches it in its UncaughtExceptionHandler, which looks something like this:

    public void onUncaughtException(Throwable ex) {

      if (mainTestHasRun && timer != null) {

        // Asynchronous mode; uncaught exceptions cause an immediate
failure.

        assert (!testIsFinished);

        reportResultsAndRunNextMethod(ex);

      } else {

        // just ignore it

      }

    }

... but because the event was triggered synchronously, the first test fails
(i.e. it's not running in async mode), and the exception gets lost, so your
tests appear to pass. This code appears to have been put in place to guard
against spurious async exceptions between test methods.
--- end edification ---

So here are all the ways I can think of for a test method to complete,
either synchronously or asynchronously. Those not explicitly marked as such
work properly.

Normal synchronous test methods:
- Test method completes successfully and synchronously.
- Test method triggers an exception synchronously (*not* from within an
event handler).

Normal asynchronous test methods:
- Test method goes into async mode, returns, then passes (called
finishTest()).
- Test method goes into async mode, returns, then fails by triggering an
exception in an event handler.
- Test method goes into async mode, returns, then fails by timing out.

Weird cases:
- Test method triggers an exception synchronously *from an event handler*.
  - As described above, the exception is thrown away from GWTTestCase's
onUncaughtException().
- Test method completes synchronously, then triggers an exception between
test methods.
  - Uncertain, but I believe it just throws away the exception, as in the
above case.
- Test method completes [a]synchronously, then triggers an exception during
the next test method.
  - The delayed exception causes the *next* test to report failure, which
seems somewhat wrong.
  - But the stack trace still shows the actual point where the exception
occurred.

What those last to "weird cases" lead me to believe is that we're not really
defending against anything by throwing away uncaught exceptions, and that we
should be able to allow all uncaught exceptions to 'fail' the current test
(even if it ends up being the wrong one). Are there any other cases I'm
missing here, or some subtle reason we can't do this?

Thanks,
joel.

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to