JUnit test presenters

6 views
Skip to first unread message

rymdbullen

unread,
Feb 1, 2012, 8:38:58 AM2/1/12
to jfxflow-discuss
Hello
I have been giving the JFX Flow a chance and so far it has been easy
to work with regards to actual development. But when I would like to
testing it's a different case.

Since JFX Flow is using the MVP pattern, it would be cool to be able
to test the presenters, as it is one of the advantages of the pattern.
But I have no clue how to do it.

If I instantiate a new presenter like this:

UserPresenter userPresenter = loader.load("/fxml/
user.fxml", applicationResourceBundle);
userDetailPresenter.setUserService(getUserService());

How will I be able to introduce the values from the view to the
presenter?

So, it would be cool to be able to test the presenters by setting the
parameters of the view and then trigger the possible actions.

Is there a way to test the presenters in this fashion?

Best Regards

Daniel Zwolenski

unread,
Feb 1, 2012, 10:39:37 PM2/1/12
to jfxflow...@googlegroups.com
Hi, 

JFX Flow is based around the MVP pattern, but FXML makes it difficult to do this cleanly (see the 'FXML Compromise' in this post: http://www.zenjava.com/2011/12/11/javafx-and-mvp-a-smorgasbord-of-design-patterns).

As a result if you use FXML then the Presenter has a pretty tight coupling with the view and it is difficult to separate them fully for testing. I haven't yet managed to put together a test approach I'm happy with. One option would be to expose the controls on your presenter (which are loaded by the FXMLLoader) and then manipulate these. Clunky.   

I am in discussions with the JFX guys about ways to make FXML work better for this sort of stuff, but Greg, who is the main FXML guy, is not overly open to a lot of the stuff needed to make this pattern clean - he views a lot of it as unnecessary bloat. We've got a few changes in the pipeline in the next release of JFX but nothing that is likely to make your particular problem easier unfortunately.  

I am just finishing a client project that was using JFX Flow (which is why I have been fairly quiet for the last month or so), and have a few lessons-learned as a result. I may be tweaking things over the next few weeks to see if I can improve things. If you have suggestions or feedback please send it through. 

Cheers, 
zonski  

Dr. Michael Paus

unread,
Feb 2, 2012, 2:59:08 AM2/2/12
to jfxflow...@googlegroups.com
Hi

> I am just finishing a client project that was using JFX Flow (which is
> why I have been fairly quiet for the last month or so), and have a few
> lessons-learned as a result. I may be tweaking things over the next
> few weeks to see if I can improve things. If you have suggestions or
> feedback please send it through.
Maybe you can share some of your lessons-learned with us. ;-)

MiPa

Daniel Zwolenski

unread,
Feb 3, 2012, 8:03:43 AM2/3/12
to jfxflow...@googlegroups.com
Good idea Michael :)

I'll start with just some high level challenges and then I'll try and put together some thoughts on solutions and get back to you guys before I do anything. Please do chime in with ideas. I'm very keen to hear from people using it as to what works and what doesn't.

I found a fair bit of clunkiness around sub-activities. I had a lot of scenarios where a parent activity contained several child ones (eg tab panes, wizards). It became difficult to aggregate things like the list of active workers, current sub-page transition, etc.

The whole activate() thing and the @Param stuff is not bad but it is only useful for top-level browser pages and not so good for sub-activities. Also I found I often wanted to get hold of the current place and edit it (eg record that a certain tab is selected so if the page is refreshed it stays on that tab), which is not well supported currently.

The dialog framework in Flow is still very weak. I ended up needing to show activities in 'light-boxes' in my app (ie popups done as top layers in a StackPane). Flow could be extended to support these.

I came up with a primitive wizard framework that could probably be cleaned up enough to be in Flow.

Similarly I got a crude form/validation framework going. It needs work but it could be evolved too.

When going 'back' to a page it reloads itself. If you are working through a list of search results you can lose your place.

Page transition framework is a little clunky still. Partly this is due to the jfx guys making their animation classes final (on a whim from what I can tell) but also there is some inelegance in my code too. I think this could be tidied. I'd also like to be able to cancel a transition mid-change.

Browser is still not as easy to customizable as I would have liked. I ended up having my own browser impl in my app, which was fine but it seems unnecessary. Room for playing on this one.

I only recently discovered you can now interact with the real web browser via jfx code when running as an applet. Looks like we could have the NavigationManager hooked up to the real browsers URL, and Back, Foward buttons, etc. Would be pretty sweet to be able to run a jfx applet as if it were a true webapp.

The way I've used the system scope for jfx in my maven pom causes a few problems when using it in another project. This just needs some time to play with it and get something clean. It's a bigger problem to do with jfx and maven in general though.

That'll do for a start.

rymdbullen

unread,
Feb 8, 2012, 8:13:29 AM2/8/12
to jfxflow-discuss
Thanks for your efforts Dan.

I really think it is vital to be able to test the code, e.g.
presenters/controllers as outlined by MVP and Passive View patterns.
To my knowledge, there is no way to test the JavafX UI with Selenium
or equivalent framework. Thats why I started a thread here and one in
the JavaFX forum.

I think the JavaFX guys need to take testing seriously... I'm sure
they do but the programming model must support testing to the full
extent.

Best Regards
Reply all
Reply to author
Forward
0 new messages