Automatic testing of GUI related private methods
- by Stein G. Strindhaug
When it comes to GUI programming (at least for web) I feel that often the only thing that would be useful to unit test is some of the private methods*. While unit testing makes perfect sense for back-end code, I feel it doesn't quite fit the GUI classes.
What is the best way to add automatic testing of these?
* Why I think the only methods useful to test is private:
Often when I write GUI classes they don't even have any public methods except for the constructor. The public methods if any is trivial, and the constructor does most of the job calling private methods.
They receive some data from server does a lot of trivial output and feeds data to the constructor of other classes contained inside it, adding listeners that calls a (more or less directly) calls the server... Most of it pretty trivial (the hardest part is the layout: css, IE, etc.) but sometimes I create some private method that does some advanced tricks, which I definitely do not want to be publicly visible (because it's closely coupled to the implementation of the layout, and likely to change), but is sufficiently complicated to break. These are often only called by the constructor or repeatedly by events in the code, not by any public methods at all.
I'd like to have a way to test this type of methods, without making it public or resorting to reflection trickery.
(BTW: I'm currently using GWT, but I feel this applies to most languages/frameworks I've used when coding for GUI)