单元测试“混合"WPF/Silverlight 控件 [英] Unit testing "hybrid" WPF/Silverlight controls

查看:31
本文介绍了单元测试“混合"WPF/Silverlight 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启动一个新的 WPF/Silverlight 自定义控件项目,并希望对此进行单元测试.但是我对如何解决这个问题有点困惑.

I'm starting a new WPF/Silverlight custom control project and wanted to do unit testing on this one. However I'm a little confused about how to approach this.

此控件将基于 WPF 和 Silverlight 的相同代码库,并使用 #ifs 和部分类进行次要分支以消除差异.我想我可以使用 NUnit、MSTest、xUnit 等为 WPF 部分编写单元测试,并使用 Silverlight 单元测试框架为 Silverlight 部分编写单元测试,但这对我来说听起来不太优雅.我要么忽略在其中一个平台上测试相同的代码而只测试不同的部分(这不是很值得信赖)要么重写两个框架的测试(这很烦人).这是正确的方法吗?

This control would be based on the same codebase for both WPF and Silverlight with minor forking using #ifs and partial classes to tame the differences. I guess I could write unit tests for WPF part with NUnit, MSTest, xUnit, etc. and for the Silverlight part with Silverlight Unit Test Framework but this doesn't sound very elegant to me. I'd have to either ignore testing identical code on one of the platforms and test only differing parts (which is not very trustworthy) or rewrite tests for 2 frameworks (which is annoying). Is this the right way to go?

我想知道是否有一些关于如何处理此任务的指南、文章和教程.有什么指点吗?

I'm wondering if there's some guidance, articles, tutorials out there on how to approach this task. Any pointers?

推荐答案

我首先尝试使用 xUnit,但在 xUnit 和 SLUT(不同的属性、语法等)中进行相同的测试有点复杂.

I tried to use xUnit first but it was kind of complicated to make same tests work in xUnit and SLUT (different attributes, syntax, etc.)

然后我对 MSTest 进行了一些基本的试验,从非常简单的测试来看,您似乎可以成功地将 MSTest 用于 WPF 部分,并使用相同的代码和一些 #ifs 等,将 SLUT 用于 Silverlight 部分.所以我会尝试走这条路,看看它在现实世界中是如何运作的.

Then I did some basic experimenting with MSTest and from very simple test it looks like you can successfully use MSTest for the WPF part and same code with some #ifs, etc. and SLUT for the Silverlight part. So I'll try to go this route and see how it works in real-world situations.

这篇关于单元测试“混合"WPF/Silverlight 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆