Automatic testing of GUI related private methods

Posted by Stein G. Strindhaug on Stack Overflow See other posts from Stack Overflow or by Stein G. Strindhaug
Published on 2010-03-25T15:18:47Z Indexed on 2010/03/26 8:03 UTC
Read the original article Hit count: 293

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)

© Stack Overflow or respective owner

Related posts about gui

Related posts about unit-testing