GWTP Presenter sample

260 views
Skip to first unread message

Bhupesh Patel

unread,
Apr 21, 2012, 6:26:44 PM4/21/12
to juk...@googlegroups.com
Hello Everyone,

I am very new to use Juckito.  I am using gwtp in one of my application, and looking into unit testing framework to test Presenters only, not view not model. Can someone please provide me any sample to start off with juckito to test Presenter?

Thanks,

Christian Goudreau

unread,
Apr 24, 2012, 11:26:36 AM4/24/12
to juk...@googlegroups.com

Bhupesh Patel

unread,
Apr 24, 2012, 12:44:33 PM4/24/12
to juk...@googlegroups.com
Thank you so much Christian. I looked at the sample and tried crating same for my presenter and now running into this initialization exception:
java.lang.NoSuchFieldError: NULL
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:54)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
at org.jukito.JukitoRunner.<init>(JukitoRunner.java:72)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I am trying to see what i am missing here. But thanks again for providing me sample.

Bhupesh Patel

unread,
Apr 24, 2012, 1:10:08 PM4/24/12
to juk...@googlegroups.com
One more thing to notice here is that, when i try to make any backend call to my server to see if i am getting data back during my unit test or not? its not working either. As i am using DispatchAsync and i can see that my code is going thru presenter method from where i am calling server side , but it does not stop for Async operation to finish. How do we test this scenario?

Bhupesh Patel

unread,
Apr 24, 2012, 6:22:36 PM4/24/12
to juk...@googlegroups.com
I fixed exception belwo but I am trying to get actionResult object back from server from my unit test. I have crated mock handler and and mock DispatchAsync also. But when i step thru this my execution never stops at "onSucess()" of my presenter. Any idea how can i make this work?

Christian Goudreau

unread,
Apr 25, 2012, 11:24:32 AM4/25/12
to juk...@googlegroups.com
You have to build an implementation of DispatchAsync that "mocks" the behavior. Mine is called : RelayDispatcher :D
--
Christian Goudreau

Bhupesh Patel

unread,
Apr 25, 2012, 12:09:58 PM4/25/12
to juk...@googlegroups.com
Hello Christian,

Thanks for the reply. I already went thru this route, but my confusion is that instead of sending back the "fake" result , I want to get "actual" result back from the server. In my implementation i cannot get result back from server thru unit test. I did look into your RelayingDispatchAsync, but cannot figure out how to get that actual result back from server

Christian Goudreau

unread,
Apr 25, 2012, 1:36:27 PM4/25/12
to juk...@googlegroups.com
Well, I don't usually suggest to do this through unit test... what you may need to build there is maybe a more general integration test, but it is doable in two step. First isolate the presenter, test it's behavior with mocked services, then Isolate the Handler test and even there, I suggest you to not really interact with the real database.

If you want a complete test that does client to server communication, I suggest you to do integration test with cucumber, selenium, jBehave and things like that.

What are you really trying to test?
--
Christian Goudreau

Bhupesh Patel

unread,
Apr 25, 2012, 1:42:39 PM4/25/12
to juk...@googlegroups.com
Oo ok, that make sense. Well in my application during my presenter's prepareFromRequest method, i make a call to server and fetch data. Once i have that data i fire couple of events and also call revealInSlot method. I was trying to test end-to-end implementation.

I am very sorry for asking you all this novice questions, but this is my first time playing around with Mocking frameworks to do unit test. Now that its more clear to me, I will dig more to find how to perform unit testing for presenter communications. As in my app i have a parent presenter which has multiple presenter widgets. I think it should be straight forward to test interactions between them using Jukito right?

Thank you very much for your help.

Christian Goudreau

unread,
Apr 25, 2012, 1:48:40 PM4/25/12
to juk...@googlegroups.com
Yes it is, but it still depend on how you're injecting them :D

There's a couple of way of doing this:

Do isolated unit test on each element, then do a more complete unit test with the composite parent.

Do isolated unit test on each element, then do an isolated test on the parent while mocking each element.

Add on top of this an Acceptance test which is basically an integration test.

My personal preference, heavily unit test complicated behavior in isolation and rely on Acceptance test for a more complete behavioral end to end test.
--
Christian Goudreau
Reply all
Reply to author
Forward
0 new messages