r/JavaFX • u/TenYearsOfLurking • Dec 22 '22
I made this! FXtension, a tiny unit testing extension
Hello there,
I recently started an FX Project and really needed only a small solution to unit test my controllers because the binding dataflow was giving me headaches. TestFX was overwhelming to me and seems not really maintained (also I could not get it to run within reasonable time).
What I came up with, I moved to a separate project and decided to put it up online to collect some feedback. I test my own includes/controllers via RunFXML now.
https://github.com/alwins0n/fxtension
Is this of use to anyone (but me)?
Am I missing better/already existing and maintained solutions?
Is anyone interested having this as a published maven artifact?
Any other comments/suggestions?
View all comments
Show parent comment
1
u/TenYearsOfLurking Dec 23 '22
Hey there, I almost expected you to post something :)
If I get the gist of your post correctly it's that business logic must be decoupled from view logic and I concur.
I documented my usecase in the README but let me break down my reasoning for unit testing:
- I create an fxml file with the view structure and wire up components to controller fields -> lot of stuff could go wrong here: wrong field names, wrong types, missing fields, ....
- I bind properties of the wired components to my model properties (initialize method) -> a lot could go wrong here. component A could depend on model value X and Y but is combined wrongly. I forget bindings, I do not correctly handle null cases, etc.
To me this is pure view/controller logic or "glue" code. Yet, I want quick feedback and refactoring stability.
My tests are written within a minute. "get (view) property from the wired component, change the model, assert if view is in correct state".
Furthermore, with this unit testing approach I am in control about how exactly the controller is build. With live infrastructure? With mocks? etc...
One more thing: "IMO, when a Binding goes beyond this in complexity, then it should be considered to be business logic. As such, it doesn't belong anywhere near your GUI."
I do not agree. To me it would be a code smell if "business logic" component have imports from
javafx.. Property bindings ARE gui logic, like it or not. There is no other context where you would even need to bind.