将 NUnit/ReSharper 测试移至 Silverlight
我们有一个 WinForms 应用程序,计划将其移植到 Silverlight。显然,UI 需要完全重写,但我们有很多业务逻辑已经通过 NUnit 进行了充分测试测试。我们使用 ReSharper 在 IDE 中运行测试,并使用 nunit-console 连续运行测试集成机。
当我们开始将业务逻辑类移入 Silverlight 程序集时,我们如何让这些单元测试针对这些 Silverlight 程序集运行?我的理解是,如果没有 重大调整,并且所说的调整(以项目模板的形式)似乎是 VS2008 和 Silverlight 3 特定的(我们很可能会在我们的移植中使用 VS2010 和 Silverlight 4)。
如果这是最佳选择,我们可以将测试转移到另一个测试框架,但除了 NUnit 之外似乎没有太多其他框架。 Silverlight 单元测试框架 看起来像是在浏览器内运行,这对于持续集成。
我知道 Silverlight 4.0 程序集可以加载到 .NET 4.0 可执行文件中,但我不确定这对于单元测试意味着什么。将我们的业务逻辑程序集编译为 Silverlight 4.0 DLL,并编写引用 Silverlight DLL 的完整框架 .NET 4.0 NUnit 测试程序集是否可行?看起来这可能可行,但是有人通过单元测试成功地做到了这一点吗?
底线是,我们应该为单元测试做什么?我们需要一个
- 仍然允许我们在 ReSharper 测试运行器中运行测试的解决方案;
- 也可以从命令行运行;
- 在 VS2010 中工作。
我们不会在测试中实例化任何 UI 对象,因此那些讨厌的 DependencyObject 线程问题不是问题。我们只需要测试我们的 Silverlight 业务逻辑。
We have a WinForms application that we're planning to port to Silverlight. Obviously the UI will need to be totally rewritten, but we have a lot of business logic that's well-tested with NUnit tests. We use ReSharper to run the tests inside the IDE, and nunit-console to run the tests on the continuous integration machines.
As we start moving our business-logic classes into Silverlight assemblies, how do we get these unit tests to run against those Silverlight assemblies? My understanding is that NUnit can't run Silverlight tests without significant tweaking, and said tweaking (in the form of a project template) appears to be VS2008- and Silverlight 3-specific (we'll most likely be using VS2010 and Silverlight 4 for our port).
We can move our tests to another testing framework if that's the best option, but there doesn't seem to be much else besides NUnit. The Silverlight Unit Test Framework looks like it runs inside the browser, which is a non-starter for continuous integration.
I'm aware that Silverlight 4.0 assemblies can be loaded into a .NET 4.0 executable, but I'm unsure of what this means for unit testing. Would it work to compile our business-logic assembly as a Silverlight 4.0 DLL, and write a full-framework .NET 4.0 NUnit test assembly that references the Silverlight DLL? It seems like this might work, but has anyone done this successfully with unit tests?
Bottom line, what should we do for our unit tests? We need a solution that
- still lets us run tests in the ReSharper test runner;
- can also be run from the command line;
- works in VS2010.
We don't instantiate any UI objects in our tests, so those pesky DependencyObject threading issues aren't a concern. We just need to test our Silverlight business logic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定是否支持 NUnit 或添加起来有多困难,但您可以查看 http://AGunit.codeplex.com 用于 ReSharper Silverlight 支持。
我为 CI silverlight 测试编写了一个小工具,并尝试在正常的 dev/tdd 场景中提供帮助 - 你可以查看 http:// StatLight.codeplex.com。
您应该能够在那里找到 silverlight 的 NUnit 构建(有一些)。不确定是否有任何运行程序可以在浏览器中使用 NUnit。但是 StatLight 可以为您运行一些基本的 NUnit 功能。
希望这能给您一点帮助。
Not sure if NUnit is supported or how difficult it would be to add, but you might check out http://AGunit.codeplex.com for ReSharper Silverlight support.
I wrote a little tool to C.I. silverlight tests and attempt to help in normal dev/tdd scenarios - you can go check out http://StatLight.codeplex.com.
You should be able to find an NUnit build for silverlight out there (there's a few). Not sure of any runners that work with NUnit in the browser. However StatLight can run some basic NUnit functionality for you.
Hope this gives you a little help.