We\'re working on a project here in Visual Studio 2008. We\'re using the built-in testing suite provided with it (the Microsoft.VisualStudio.TestTools.UnitTesting namespace
This is all well and good for regular application unit testing ... but if you are building user controls that need unit tests for the control behaviors and states, it needs a unit test framework too. NUnitForms might be the answer for you - personally I need to check it out myself.
Check out Jeremy D. Miller's WIP Presentation Patterns wiki page for refactoring inspiration :)
Miller is writing a book, and it looks like it's going to be a must-have for this sort of thing.
I use the Passive View architecture as detailed here http://martinfowler.com/eaaDev/PassiveScreen.html
Basically move all your code in the forms to a separate class called the xxxUI. The form then implements a IxxxUI interface and expose anything that the xxxUI class needs. You can probably simplify things and aggregate dealing with several controls into one method.
The flow then goes The USER click on a button. The button calls a method on the corresponding UI class. Passing any needed parameters. The UI Class method modifies the model. Then using the interface updates the UI.
For unit testing you have test or dummy classes implement the interfaces and register themselves with the UI Classes. You can have these test classes fire any type of input and respond accordingly. Typically I have sequence lists that do thing in a precise order. (Tap A, click this, scroll that, then Type B, etc).
I've used NUnitForms when it comes to testing my own UI controls with good results! I would agree with the others on refactoring if you are using standard (or well tested) UI controls.
If the focus is on testing the actual controls I would use NUnitForms as it can be extended to support your new controls. Anyhow if you're not to involve any manual testing you will need a lib that can do "image based" analysis of the displayed end result.
I've tried TestComplete for this but I though it to be a bit too pricey since I could code a similar lib for just the image comparison in c#. So my plan would be to test the controls separately and then refactor the UI as mentioned my the others.
For Windows 10, Microsoft now recommends Appium with WinAppDriver. VS 2019 will be the last version containing Microsoft Coded UI.
https://docs.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code?view=vs-2019
You should use Microsoft Coded UI to test the UI layer. This involves writing (or recording) tests that mimic actions that a user would perform and writing assert statements to ensure that the correct output is achieved.
Of course, this is arguable not unit testing, because it is difficult to create actions from the front end that test a single unit of work and is not a replacement for other unit testing. I agree also that the front end business logic should be a thin as possible. However, this will fill any gaps where your unit tests do not cover. Hopefully only small units of work will be not covered by your unit tests, so that the coded UI tests will catch the remaining untested units.
Coded UI comes built in with the latest versions of Visual Studio Premium. I suggest that you do not just use the record functionality, but instead learn how to write the tests yourself as this gives you greater flexibility.