开发者

C# - WPF : testing strategies

开发者 https://www.devze.com 2023-01-18 12:37 出处:网络
I\'m new to C# 4.0 and WPF and I\'m about to start a new application. Comin开发者_运维技巧g from a C++/MFC world, I\'m interested in testing strategies used with the up to date technologies.

I'm new to C# 4.0 and WPF and I'm about to start a new application.

Comin开发者_运维技巧g from a C++/MFC world, I'm interested in testing strategies used with the up to date technologies.

For instance:

  • Unit Testing
  • Functional testing
  • UI Testing
  • other?

Any advice would be appreciated.

Thanks.


As Larry said White UI test framework can be used for UI testing WPF. This post explains this in more detail -

Testing WPF applications with the White UI Test framework: http://blogs.msdn.com/b/john_daddamio/archive/2008/04/04/testing-wpf-applications-with-the-white-ui-test-framework.aspx

Also have look at this article to know how to automate the UI testing:

Automating UI Tests In WPF Applications: http://msdn.microsoft.com/en-us/magazine/dd483216.aspx

Xaml team has come up with a XAML Compliance Suite to verify XAML(I haven't tried it myself though) -

http://blogs.msdn.com/b/llobo/archive/2010/07/07/xaml-compliance-suite-v1.aspx

Various third-party tools are also available for testing WPF application, like this one from AutomatedQA -

AutomatedQA’s TestComplete is a comprehensive automated testing tool that helps QA teams automate their functional, unit, regression and other testing types for a wide variety of application types, including Windows Presentation Foundation (WPF) applications.

http://www.automatedqa.com/products/testcomplete/testing-wpf-apps/

I would also suggest you to go through WPF Application Quality Guide from MS

This document provides an overview of testing Windows Presentation Foundation (WPF) applications and controls.

http://windowsclient.net/wpf/white-papers/wpf-app-quality-guide.aspx#intro


Take a look at White. From their site:

White Automate windows applications https://white-project.googlecode.com/svn/

White is a framework for automating rich client applications based on Win32, WinForms, WPF, Silverlight and SWT (Java) platforms. It is .NET based and does not require the use of any proprietary scripting languages. Tests/automation programs using White can be written with whatever .NET language, IDE and tools you are already using. White provides a consistent object-oriented API, hiding the complexity of Microsoft's UIAutomation library (on which White is based) and windows messages. Only stable versions of White are released, so all releases are production-ready.


These days most people that care about unit testing of WPF tend to make use of the MODEL-VIEW-VIEWMODEL (MVVM) design pattern. This is a tag on stackoverflow about it.

This lets you unit-test most of your code (including a lot of the UI logic) without WPF getting in the way.

For system testing see the other answers to this questions.


As already mentioned, the MVVM pattern (or even the Model-View-ViewModel-Presenter pattern) is a good start. They allow you to separately and isolated test the different concerns of the application.

A good tool for the unit testing part is Moq . I use it a lot.

I also do often acceptance tests from the ViewModel down to the Model and Presenter. So I can assure that all layers work together. This is a compromise between UI testing and unit testing. It has the advantage that the tests run faster and therefore are run more often.

If you also want to automatically test the correct data binding between the View and the ViewModel you should check out Guia. It allows you to directly instantiate and test a single UserControl.


I care a lot about the view looking right. That means unit testing. For me, the best technique is to ONLY test the view in a single unit test, that means

model + view = result.

The open source verification utility ApprovalTests (www.approvaltests.com or nuget ) will easily test Wpf views.

You can see it in action here: http://www.youtube.com/watch?v=Xc_ty03lZ9U

I'd recommend watching the winforms video 1st though, as it goes into more of the theory of how to test views in general: http://www.youtube.com/watch?v=hKeKBjoSfJ8

The code itself will look like

var model = CreateModel();
var yourWpfView = new YourWpfView(model);
WpfApprovals.Verify(yourWpfView);

and it will take a screenshot and compare it against a golden master.

0

精彩评论

暂无评论...
验证码 换一张
取 消