On Oct 6, 11:02 am, Didier DURAND <durand.did...@gmail.com> wrote:
> Hello,
>
> To improve the coverage of my automated tests, I'd like to test my own
> GWT.UncaughtExceptionHandler within a GWTTestCase to see if it
> functions correctly.
>
> I can't do it for now: the JUnit test always fails.
>
> Can you help me an let me know what's wrong in my code below ? (I
> tried to use an asynchronous test to make sure that I am going through
> the ExceptionHandler)

You're not testing your exception handler here, you're testing whether
GWT will call the registered exception handler. This kind of test
should be in GWT itself; you shouldn't test in your own code whether
GWT functions the way it's supposed to.
To test your handler, you should instantiate it and directly call
onUncaughtException to see if it behaves the way you want. What's left
is to ensure your handler is correctly registered as the uncaught
exception handler; but I wonder if this is something to test in a
GWTTestCase... (FYI GWTTestCase *controls* the uncaught exception
handler)

> thanks
> didier
>
> public class TestExceptionHandler extends GWTTestCase {
>
>         public void testWithHandler() {
>                 ExceptionHandler handler = new
> ExceptionHandler(GWT.getUncaughtExceptionHandler());
>                 GWT.setUncaughtExceptionHandler(handler);
>                 this.delayTestFinish(1000);
>                 throw new ClientException("test");
>         }
>
>         private class ExceptionHandler implements
> GWT.UncaughtExceptionHandler {
>
>                 private GWT.UncaughtExceptionHandler handler;
>
>                 public ExceptionHandler(GWT.UncaughtExceptionHandler h) {
>                         this.handler = h;
>                 }
>
>                 @Override
>                 public void onUncaughtException(Throwable e) {
>                         System.out.println("Exception handler called!");
>                         TestExceptionHandler.this.finishTest();
>                         this.handler.onUncaughtException(e);
>                 }
>         }
>
>       �...@override
>         public String getModuleName() {
>                 return "MyModule";
>         }
>
>
>
>
>
>
>
> }

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to