<p>We are working on a large project with a measure of new/modified GUI functionality.  We've found in the past that we often introduced new problems in related code when adding new functionality.</p>
<p>We have non-technical users perform testing, but they often miss parts and allow bugs to slip through.</p>
<p>Are there any best practices for organizing the UI testing of a WinForms project?  Is there any way to automate it?</p>

[{'answer_id': 41607, 'author': 'jodonnell', 'author_id': 4223, 'author_profile': 'https://Stackoverflow.com/users/4223', 'pm_score': 5, 'selected': True, 'text': "<p>There are GUI testing tools that will click buttons and stuff for you but they're pretty fragile in my experience.</p>\n\n<p>The best thing to do is to keep your UI layer as thin as possible.  Your event handler classes should optimally be only one or two lines that call out to other more testable classes.  That way you can test your business logic in unit tests without having to actually do a button click.</p>\n"}, {'answer_id': 41608, 'author': 'Anthony Mastrean', 'author_id': 3619, 'author_profile': 'https://Stackoverflow.com/users/3619', 'pm_score': 0, 'selected': False, 'text': '<p>I can\'t really help with organization or best practices, but an <a href="http://www.nunit.org/index.php" rel="nofollow noreferrer">NUnit</a> extension appears to be available for forms testing, <a href="http://www.google.com/search?q=nunitforms" rel="nofollow noreferrer">NUnitForms</a>.</p>\n'}, {'answer_id': 41614, 'author': 'khebbie', 'author_id': 4189, 'author_profile': 'https://Stackoverflow.com/users/4189', 'pm_score': 1, 'selected': False, 'text': '<p>The following book is an introduction to the subject.\nThere are as many ways as there are developers out there..</p>\n\n<p><a href="http://pragprog.com/titles/idgtr/scripted-gui-testing-with-ruby" rel="nofollow noreferrer">http://pragprog.com/titles/idgtr/scripted-gui-testing-with-ruby</a></p>\n'}, {'answer_id': 41621, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 3, 'selected': False, 'text': '<p>You can automate GUI testing using <a href="http://www.codeplex.com/white" rel="noreferrer">White</a> framework.</p>\n\n<p>Also consider using TDD friendly design, i.e. use <a href="http://en.wikipedia.org/wiki/Model-view-controller" rel="noreferrer">MVP/MVC</a> pattern.</p>\n\n<p>I would highly recommend you to read documentation from Microsoft patterns&amp;practies teams. </p>\n\n<p>Especially have a look at the <a href="http://msdn.microsoft.com/en-us/library/aa480450.aspx" rel="noreferrer">Composite UI application block</a> and <a href="http://www.codeplex.com/CompositeWPF" rel="noreferrer">CompositeWPF</a>.  </p>\n\n<p>These projects specifically designed to give you best practices in GUI apps development including test driven UI.</p>\n'}, {'answer_id': 41653, 'author': 'Brian Stewart', 'author_id': 3114, 'author_profile': 'https://Stackoverflow.com/users/3114', 'pm_score': 2, 'selected': False, 'text': '<p>Keep the GUI layer as thin as possible. Michael Feathers article, <a href="http://www.objectmentor.com/resources/articles/TheHumbleDialogBox.pdf" rel="nofollow noreferrer">The Humble Dialog Box</a>, is a classic. Also check out Martin Fowler\'s <a href="http://martinfowler.com/eaaDev/PassiveScreen.html" rel="nofollow noreferrer">Passive View</a>. I have also heard that the "automatic button clickers" are fragile, and that it\'s easy to spend more time maintaining the test than you spend maintaining the code.</p>\n'}, {'answer_id': 41718, 'author': 'Sam Warwick', 'author_id': 3873, 'author_profile': 'https://Stackoverflow.com/users/3873', 'pm_score': 1, 'selected': False, 'text': '<p>There are many tools and libraries available that can automate WinForms testing, ranging from open source solutions like White to the expensive commercial solutions such as HP QuickTest Pro. There is also the UIAutomation namespace in .NET if you want to roll your own automation framework. But the real cost of automation is in the time and specialised skills it requires to implement. Maintainability is also one of the most important aspects of automated test design; you dont want to expend excessive resource keeping the automation assets current with your application. There are also lots of factors influencing the decision to automate which will be specific to your specific application and organisation.</p>\n\n<p>Your best bet will be to do some more research on the subject and check out some of the specialised testing sites such as <a href="http://www.sqaforums.com" rel="nofollow noreferrer">http://www.sqaforums.com</a>.</p>\n'}, {'answer_id': 42659, 'author': 'Mark Witczak', 'author_id': 1536194, 'author_profile': 'https://Stackoverflow.com/users/1536194', 'pm_score': 1, 'selected': False, 'text': '<p>I found this quick and dirty way to test web page layouts in various browsers. It\'s called <a href="http://browsershots.org/" rel="nofollow noreferrer">browsershots.org</a>. Our client requires support in 5 browsers right now and that takes about a week for full regression testing. This service will deliver screenshots of some 70+ browsers and versions. I print them out and hold up the pages to the light. If they don\'t line up, there must be a layout problem.</p>\n'}, {'answer_id': 226539, 'author': 'Kurt W. Leucht', 'author_id': 27687, 'author_profile': 'https://Stackoverflow.com/users/27687', 'pm_score': 0, 'selected': False, 'text': '<p>I used a trial download similar to this product (<a href="http://www.tethyssolutions.com/product.htm" rel="nofollow noreferrer">http://www.tethyssolutions.com/product.htm</a>) and this product (<a href="http://www.mjtnet.com/macro_scheduler.htm" rel="nofollow noreferrer">http://www.mjtnet.com/macro_scheduler.htm</a>) years ago and I was happy with the results.  These are pretty cheap solutions and some of these macro recorder products can actually be used for automated testing.  </p>\n'}, {'answer_id': 8146390, 'author': 'dodgy_coder', 'author_id': 507950, 'author_profile': 'https://Stackoverflow.com/users/507950', 'pm_score': 0, 'selected': False, 'text': '<p>A new method available now is using Ruby, via the Ruby gem called <a href="http://www.gearheadforhire.com/articles/ruby/win32-autogui/using-ruby-to-drive-windows-applications" rel="nofollow">win32-autogui</a>. This provides a framework for testing Windows GUI apps. Combine it with Ruby tools RSpec and Cucumber, and it makes for quite a powerful testing framework.</p>\n'}, {'answer_id': 12256279, 'author': 'Caesar Anders', 'author_id': 1029038, 'author_profile': 'https://Stackoverflow.com/users/1029038', 'pm_score': 0, 'selected': False, 'text': '<p>How to organize UI testing depends on how you design the test cases.</p>\n\n<p>Automating Windows Forms application in unit test level can use TDD framework, such as NUnit; or use BDD framework, such as NSpec.</p>\n\n<p>Automating Windows Forms applications in functional testing level can use White, CodedUI, or even directly using <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd561932%28v=vs.85%29.aspx" rel="nofollow">Windows Automation API 3.0</a> (UI Automation and MSAA).</p>\n\n<p>Since all these stuffs mentioned above are technologies rather than solutions, it\'s better to build some fundamental test automation/scripting frameworks based on these technologies before you start to write automated tests.</p>\n'}, {'answer_id': 26027143, 'author': 'Amanda Sullivan', 'author_id': 4071056, 'author_profile': 'https://Stackoverflow.com/users/4071056', 'pm_score': 2, 'selected': False, 'text': '<p>In the event that someone finds this useful: </p>\n\n<p><a href="http://en.wikipedia.org/w/index.php?title=List_of_GUI_testing_tools" rel="nofollow">List of GUI testing tools</a> found on Wikipedia.</p>\n'}]
['https://Stackoverflow.com/questions/41601', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4392/']