Testing the complex User control WinForms

I am developing a rather complex .NET custom element (40K lines of code), but some problems with testing it.

I have made several sample projects that demonstrate the basic functions of a control, but only a small subset of the states and operations of the control can be checked.

Unit tests are also useless due to these problems:

  • a huge number of use cases (for example, the description of the "choice of elements" may take about 4 pages of specifications)
  • many ways to do the same thing (as well as from user code or GUI)
  • a control has many sub-state states, and everything may not work in every state
  • How to test development time support?

I know this is a common GUI testing issue, so I would like to ask you if there are any well established methods for testing custom visual components ?

Thanks for any advice.

+4
source share
1 answer

The main thing is to limit GUI testing to a minimum, because this is the most expensive way to test. In the 40 kilogram lines of code, I believe that 90% of the code doesn't work with WinForm GUI elements at all. Thus, most of them can be covered by unit tests, but it depends on how you structure your code.

What to consider:

  • SOLID principles, especially the principle of single responsibility (SRP) - instead of several huge classes of β€œGod”, you should rely on a large number of small β€œservice” interfaces and classes that do only one thing and do it well, you can write separate tests for them, and then assemble them into a larger picture as soon as you know that they are working fine.
  • MVP template (actually passive viewing): WinForm GUI code should only be a thin layer (View), everything else should be in presenters and models.
  • Presenter First approach .

I am working on a relatively complex WinForms application , and these templates have never failed me.

As for GUI testing, I use UI Automation , but only for some standard cases. Everything else is covered by testing without using a graphical interface.

+1
source

All Articles