How can I unit test a GUI?

后端 未结 14 1396
迷失自我
迷失自我 2020-11-30 17:25

The calculations in my code are well-tested, but because there is so much GUI code, my overall code coverage is lower than I\'d like. Are there any guidelines on unit-testin

14条回答
  •  悲&欢浪女
    2020-11-30 18:01

    If you are using Swing, FEST-Swing is useful for driving your GUI and testing assertions. It makes it pretty straightforward to test things like "if I click button A, dialog B should be displayed" or "if I select option 2 from the drop-down, all the checkboxes should become deselected".

    The graph scenario that you mention is not so easy to test. It's pretty easy to get code coverage for GUI components just by creating and displaying them (and perhaps driving them with FEST). However, making meaningful assertions is the hard part (and code coverage without meaningful assertions is an exercise in self-deception). How do you test that the graph was not drawn upside-down, or too small?

    I think that you just have to accept that some aspects of GUIs cannot be tested effectively by automated unit tests and that you will have to test them in other ways.

提交回复
热议问题