I am working on开发者_高级运维 Swing, I want to know how to effectively do TDD for my GUI applications.
I have already done something using abbot and fest... but i still feel it is not effective, it
is like doing Functional testing
only, if any one having good suggestions please post..
There are two aspects to TDD the GUI. There is the GUI setup itself (say drag and drop) and then there is what the GUI does (press this button launches a URL in a web browser).
Regarding the GUI itself, I recommend Test Just After, where you write a bit of code and see that Swing actually does what you expect it to do, and then you put that code into a testable method that locks down the behavior. You still keep it small so your need to test drives the design somewhat, but in the end of the day the Swing framework drives the design more.
Regarding what the GUI does, you keep the untested part as thin as possible, and write a test first for a method call that does what you need. For example, the adding of the action listener may go untested, but the action listener does nothing more than delegate to a method that is under test.
At a certain point you have to remember that this is unit testing, so it is certainly possible for all your tests to pass and Swing still not behave how you want. Don't expect TDD to give you better. Functional tests have their place as well.
I found that Abbot can potentially help with the first kind of Test Just After, but not enough to justify the extra tool (in our project we have frameworks coming out of our ears, so I try to be judicious about how many we use).
精彩评论