how to test "presenter" that is "activity"

81 views
Skip to first unread message

tanteanni

unread,
Aug 17, 2011, 8:03:43 AM8/17/11
to google-we...@googlegroups.com
On of the main advantages of MVP-patrtern propagated is testability because if implemented "correctly" there is no need for GWTTestCase. But if i use MVP in conjunction with "activities & places" - meaning presenters become "activities" - this advantage seem to gone?! Beeing a presenter and activity at the same time means knowing something about PlaceController - to go to other places or to deserialize the state of current place. (If PlaceController is involved the need for GWTTestCase arose.)

At the moment i see some alternatives:
- testing the "old" way with GWTTestCase
- separating activity and presenter (separating navigation logic from business-logic, the pattern is know "MVPA")
- make activity more testable (how? give a null-PlaceController in constructor?)

My Question is: Is there a best or at least good practice to test/implement such presenters? (the first 2 alternative are the worst in imho)

Nicolas Antoniazzi

unread,
Aug 17, 2011, 9:02:49 AM8/17/11
to google-we...@googlegroups.com
If you use MVP, you might use some kind of factory for your objects, like the PlaceController.
The best is to use dependency injection for this (with Gin).
The PlaceController is Injected in the Activity (or in your custom factory).

When it comes to testing, you can use a special factory (or injection) that implements a Testable PlaceController)


2011/8/17 tanteanni <tant...@hotmail.com>

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

tanteanni

unread,
Aug 17, 2011, 9:13:33 AM8/17/11
to google-we...@googlegroups.com
thx i already use gin. but how to get a testable PlaceController - Placecontroller is a class not an interface? my only idea is to give null?

Nicolas Antoniazzi

unread,
Aug 17, 2011, 9:20:35 AM8/17/11
to google-we...@googlegroups.com
Yes, indeed, I did not realized this !
That's a good question :) !

2011/8/17 tanteanni <tant...@hotmail.com>
thx i already use gin. but how to get a testable PlaceController - Placecontroller is a class not an interface? my only idea is to give null?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Nicolas Antoniazzi

unread,
Aug 17, 2011, 9:23:51 AM8/17/11
to google-we...@googlegroups.com
One solution could be to create an interface in your project around PlaceController and bind this interface on an inherited version of PlaceController. Then, inject the interface instead of the concrete implementation.

But there is certainly an easyier way of doing it...

2011/8/17 Nicolas Antoniazzi <nicolas.a...@gmail.com>

objectuser

unread,
Aug 17, 2011, 9:41:53 AM8/17/11
to google-we...@googlegroups.com
Maybe I'm not understanding the issue, but can't you just create a place controller like so:

@Provides
@Singleton
PlaceController createPlaceController(EventBus eventBus, PlaceController.Delegate delegate) {
    return new PlaceController(eventBus, delegate);
}

Put whatever in the delegate you like (I put a mock in there and ignore it).  It works for me in unit tests.

placeController.goTo(new MyPlace());


tanteanni

unread,
Aug 17, 2011, 9:45:49 AM8/17/11
to google-we...@googlegroups.com
i didn't know about this nice constructor - thx objectuser!

i'll try it :-)

tanteanni

unread,
Aug 17, 2011, 10:00:20 AM8/17/11
to google-we...@googlegroups.com
on additional question about the mock PlaceController: i guess the normal PlaceController is the source of PlaceChangeEvents, isn't it? Is it possible to let the mock fire such events on call of goTo in PlaceController? (Will the PlaceController delegate goTo-calls to it's delegate?)
it would be great if i could test the navigation logic without gwtTestcase

objectuser

unread,
Aug 17, 2011, 10:11:44 AM8/17/11
to google-we...@googlegroups.com
The delegate appears to be irrelevant in unit tests.  I test my navigation using placeController.goTo as I show above.  My activities start, stop, etc.  So it works out very well, I think.

tanteanni

unread,
Aug 17, 2011, 10:16:07 AM8/17/11
to google-we...@googlegroups.com
that means the PlaceController works as always?! it delgates only the GwtTestCase-needed-stuff? - great!

objectuser

unread,
Aug 17, 2011, 10:52:28 AM8/17/11
to google-we...@googlegroups.com
It works for me.  These are just JUnit tests (Jukito tests, specifically).

tanteanni

unread,
Aug 18, 2011, 3:24:26 AM8/18/11
to google-we...@googlegroups.com
thx for "Jukito" !!
Reply all
Reply to author
Forward
0 new messages