Testing WinForms Apps (the easy way!)
It’s been an interesting month. Because our team is involved in so many different areas, we are always learning something new! Two developments in the testing area are that one of our developers figured out how to write unit tests for Add-In tools and we started using NUnitForms for testing C# Forms applications.
NUnitForms is an extension of the NUnit test harness. It allows you to test Windows Forms applications without having to use the Reflection namespace yourself. You can just instantiate a form, display it and then use test control objects to access the controls on the form you are testing.
NUnitForms provides test classes for many common form controls. It is also fairly easy to write custom test classes for custom controls that your form might use. I started using NUnitForms over the summer to test a “hobby” application I wrote.
That application used at least a dozen forms plus various message box displays. I had started testing the application (more like trying to test it!) using reflection last winter. It was too time consuming because I was starting from scratch. No test libraries; nothing to build on. So, I quickly gave up the idea of automated testing. After I discovered NUnitForms, I quickly got traction and within 6 weeks (working only a few hours on the weekends) developed enough tests to drive the code coverage up to 97%.
Recently, I used NUnitForms to write some scenario level tests for an application our team is about to release. We had some good unit tests for one DLL in the application but no tests for the application itself because everything was in the GUI classes. In less than two weeks, I developed 14 NUnitForms test cases which covered all the basic usage scenarios and provided 82% code coverage. The code coverage results showed us how we can easily improve the application’s code coverage by 10%. The remaining 8% is in exception handling so that would be more difficult to test.
I’ll post more about NUnitForms in the near future. Meanwhile, if you want to check it out, their website is https://nunitforms.sourceforge.net/index.html