Is there any way to automate windows forms testing

2019-01-16 09:02发布

I am familiar with nunit for unit testing of the business layer however I am looking now to automate the test of the win forms gui layer.

I have seen watin and the watin recorder for automating tests on web application by accessing the controls and automating them. However I am struggling to find a watin equivalent for windows forms (written in c# or vb.net) preferably that is open source.

Does one exist or are all products based on recording mouse and keyboard presses?

Update: I have looked at this blog post on white and it seems the sort of thing I am looking for. The blog post raises some issues but as white is only in version 0.6 these may be resolved. Be interested if others have used white or any others for comparison.

7条回答
对你真心纯属浪费
2楼-- · 2019-01-16 09:20

You may consider using Coded UI, a Visual Studio built-in feature and part of the UI Automation:

Automated tests that drive your application through its user interface (UI) are known as coded UI tests (CUITs). These tests include functional testing of the UI controls. They let you verify that the whole application, including its user interface, is functioning correctly. Coded UI Tests are particularly useful where there is validation or other logic in the user interface, for example in a web page. They are also frequently used to automate an existing manual test.

[...] a typical development experience might be one where, initially, you simply build your application (F5) and click through the UI controls to verify that things are working correctly. You then might decide to create a coded test so that you don’t need to continue to test the application manually. Depending on the particular functionality being tested in your application, you can write code for either a functional test, or for an integration test that might or might not include testing at the UI level. If you simply want to directly access some business logic, you might code a unit test. However, under certain circumstances, it can be beneficial to include testing of the various UI controls in your application. A coded UI test can automate the initial (F5) scenario, verifying that code churn does not impact the functionality of your application.

Read more at: https://docs.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code

查看更多
祖国的老花朵
3楼-- · 2019-01-16 09:25

Check out http://www.codeplex.com/white and http://nunitforms.sourceforge.net/. We've used the White project with success.

Same Answer to a previous question

查看更多
Summer. ? 凉城
4楼-- · 2019-01-16 09:28

Here are some links from MSDN Magazine on automatic testing code:

  • Using UIAutomation Bugslayer March 2007
  • Using PowerShell Test Run December 2007
  • Tester, a utility for recording mouse clicks and keystrokes, then playing them back & program checking behaviour. Excellent for unmanaged code. Uses windows handles so may not work well for managed code. Bugslayer March 2002.
查看更多
对你真心纯属浪费
5楼-- · 2019-01-16 09:30

AutomatedQA's TestComplete is a good testing application to automate GUI testing. It supports more than just Windows Forms also, so you can reuse it for other applications. It is not open source and this is the best that I have found. I haven't seen an open source equivalent to WatiN. It does have a free trial, for you decide if you like it or not. The main reason I went with it, is that it really is cost effective, compared to other testing applications.

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-16 09:34

You could check out the Microsoft UI Automation framework. This has been included in .NET since version 3.0. This is actually what the White framework uses anyway.

查看更多
时光不老,我们不散
7楼-- · 2019-01-16 09:44

As a new alternative, I can give you FlaUI (https://github.com/Roemer/FlaUI). It is basically a complete re-write of white with more features and a clean code-base.

查看更多
登录 后发表回答