C# 有什么方法可以自动进行 Windows 窗体测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any way to automate windows forms testing?
提问by John
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.
我熟悉 nunit 用于业务层的单元测试,但是我现在正在寻找自动化 win 表单 gui 层的测试。
I have seen watinand 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.
我已经看到watin和 watin 记录器通过访问控件并自动化它们来自动化 Web 应用程序的测试。但是,我正在努力寻找 Windows 窗体(用 c# 或 vb.net 编写)的 watin 等效项,最好是开源的。
Does one exist or are all products based on recording mouse and keyboard presses?
是否存在一种或所有产品都基于记录鼠标和键盘按下情况?
Update:I have looked at this blog post on whiteand 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.
更新:我看过这篇关于白色的博客文章,这似乎是我正在寻找的东西。博客文章提出了一些问题,但由于白色仅在 0.6 版中,这些问题可能会得到解决。如果其他人使用白色或任何其他人进行比较,请感兴趣。
采纳答案by denis phillips
Check out http://www.codeplex.com/whiteand http://nunitforms.sourceforge.net/. We've used the White project with success.
查看http://www.codeplex.com/white和http://nunitforms.sourceforge.net/。我们成功地使用了 White 项目。
Same Answer to a previous question
上一个问题的相同答案
Edit
编辑
The White project has moved, and is now located on GitHubas part of TestStack.
White 项目已经移动,现在作为 TestStack 的一部分位于GitHub 上。
回答by Dale Ragan
AutomatedQA's TestCompleteis 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.
AutomatedQA 的 TestComplete是一个很好的自动化 GUI 测试的测试应用程序。它不仅支持 Windows 窗体,还支持其他应用程序。它不是开源的,这是我发现的最好的。我还没有看到相当于 WatiN 的开源软件。它确实有免费试用版,由您决定是否喜欢。我选择它的主要原因是,与其他测试应用程序相比,它确实具有成本效益。
回答by Sam Warwick
You could check out the Microsoft UI Automationframework. This has been included in .NET since version 3.0. This is actually what the White framework uses anyway.
您可以查看 Microsoft UI 自动化框架。自 3.0 版以来,这已包含在 .NET 中。无论如何,这实际上是 White 框架所使用的。
回答by Bruce McLeod
As far as I know, Whiteis an abstraction layer over the top of Microsoft's UI Automationframework. I have written a similar layer that we use internally on our projects and it works great. So White would definattley be worth a look
据我所知,White是微软UI 自动化框架之上的一个抽象层。我写了一个类似的层,我们在我们的项目内部使用它,它工作得很好。所以怀特绝对值得一看
Microsoft have released the source to UI Automation, so if necessary you should be able to debug right down the whole stack if necessary.
Microsoft 已经发布了 UI 自动化的源代码,因此如有必要,您应该能够在整个堆栈中进行调试。
The really cool thing is that with licence cost, you can scale up and run as many machines as you like for execution.
真正酷的是,通过许可成本,您可以扩展并运行任意数量的机器来执行。
We run inside VSTS and link our results to requirements, but you can use c# express and nUnit and get first class tools and languages for little to no cost.
我们在 VSTS 中运行并将我们的结果链接到需求,但是您可以使用 c# express 和 nUnit 并以很少甚至免费的成本获得一流的工具和语言。
回答by MarkJ
Here are some links from MSDN Magazine on automatic testing code:
以下是 MSDN 杂志中有关自动测试代码的一些链接:
- Using UIAutomation BugslayerMarch 2007
- Using PowerShell Test RunDecember 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. BugslayerMarch 2002.
- 使用UIAutomation Bugslayer2007 年 3 月
- 使用 PowerShell测试运行2007 年 12 月
- Tester,一个用于记录鼠标点击和击键,然后回放它们和程序检查行为的实用程序。非常适合非托管代码。使用 Windows 句柄,因此可能不适用于托管代码。 Bugslayer2002 年 3 月。
回答by Roemer
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.
作为一个新的选择,我可以给你 FlaUI ( https://github.com/Roemer/FlaUI)。它基本上是对白色的完全重写,具有更多功能和干净的代码库。
回答by Dariusz Wo?niak
You may consider using Coded UI, a Visual Studio built-in feature and part of the UI Automation:
您可以考虑使用Coded UI,这是 Visual Studio 的内置功能和 UI 自动化的一部分:
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.
通过其用户界面 (UI) 驱动应用程序的自动化测试称为编码 UI 测试 (CUIT)。这些测试包括 UI 控件的功能测试。它们让您验证整个应用程序(包括其用户界面)是否正常运行。编码 UI 测试在用户界面中存在验证或其他逻辑的情况下特别有用,例如在网页中。它们还经常用于自动化现有的手动测试。
[...] 典型的开发体验可能是这样一种体验:最初,您只需构建应用程序 (F5) 并单击 UI 控件以验证事情是否正常工作。然后您可能决定创建一个编码测试,这样您就不需要继续手动测试应用程序。根据应用程序中正在测试的特定功能,您可以为功能测试或集成测试编写代码,这些测试可能包括也可能不包括 UI 级别的测试。如果您只是想直接访问某些业务逻辑,则可以编写单元测试。但是,在某些情况下,在您的应用程序中包含对各种 UI 控件的测试可能是有益的。编码的 UI 测试可以自动化初始 (F5) 场景,
Read more at: https://docs.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code
阅读更多信息:https: //docs.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code