Unit testing a Swing component

后端 未结 5 1856
清歌不尽
清歌不尽 2021-02-19 22:25

I am writing a TotalCommander-like application. I have a separate component for file list, and a model for it. Model support listeners and issues a notification for events like

5条回答
  •  悲哀的现实
    2021-02-19 22:52

    Note, generally speaking unit testing on UI stuff is always difficult because you have to mock out a lot of stuff which is just not available.
    Therefore the main aim when developing applications (of any type) is always to try to separate UI stuff from the main application logic as much as possible. Having strong dependencies here, make unit testing really hard, a nightmare basically. This is usually leveraged by using patterns like a MVC kind of approach, where you mainly test your controller classes and your view classes do nothing than constructing the UI and delegating their actions and events to the controllers. This separates responsibilities and makes testing easier.

    Moreover you shouldn't necessarily test things which are provided by the framework already such as testing whether events are correctly fired. You should just test the logic you're writing by yourself.

提交回复
热议问题