简体   繁体   English

使用NUnit在Silverlight 4应用程序中对WCF RIA服务进行单元测试

[英]Using NUnit to unit test WCF RIA Services in a Silverlight 4 App

I have recently tried using the Silverlight NUnit Project template (the one from Jamie Cansdale found here ) for a Silverlight 4 project that uses WCF RIA 1.0. 我最近尝试使用Silverlight的NUnit的项目模板(杰米Cansdale一个发现这里 ),它使用WCF RIA 1.0 Silverlight 4的项目。 I seem to be close, but I still cannot get it to work. 我似乎很近,但是我仍然无法使它正常工作。

Here's what I've done 这就是我所做的

  1. Create project. 创建项目。 :) :)
  2. Change Silverlight version to 4. 将Silverlight版本更改为4。
  3. Set the WCF RIA Services Link to my WCF RIA project. 将WCF RIA服务链接设置为我的WCF RIA项目。
  4. Make sure that all of the references (except for mscorlib) are CopyLocal=True. 确保所有引用(mscorlib除外)均为CopyLocal = True。
  5. Try to run the tests. 尝试运行测试。

What happens? 怎么了?

The test fixture setup (which contains only the line "_context = new MyContext();") dies with this exception: 测试夹具设置(仅包含“ _context = new MyContext();”行)因以下原因而死亡:

1 test failed: SetUp : System.TypeInitializationException : The type initializer for 'MS.Internal.JoltHelper' threw an exception. 1个测试失败:SetUp:System.TypeInitializationException:'MS.Internal.JoltHelper'的类型初始化程序引发了异常。 --- ---

Has anyone else been able to use the template to test against WCF RIA projects? 其他人是否能够使用该模板针对WCF RIA项目进行测试?

The NUnit console doesn't support silverlight. NUnit控制台不支持silverlight。 See: http://greenicicleblog.com/2010/04/27/nunit-for-silverlight-updated/ (Search for "Is there a way to run these in nunit-console?") 请参阅: http ://greenicicleblog.com/2010/04/27/nunit-for-silverlight-updated/(搜索“是否有办法在nunit-console中运行它们?”)

You can get a Silverlight port of NUinit from google code (from link above) but then you've got to use the Silverlight Test runner as described in the first link above. 您可以从Google代码(从上面的链接)获得NUinit的Silverlight端口,但是您必须按照上面的第一个链接所述使用Silverlight测试运行程序。 This is OK for manually running the tests, but not useful in a continuous integration scenario. 可以手动运行测试,但是在连续集成方案中没有用。

The problem is that when the tests run in NUnit console, I believe it runs in the CLR, not the Silverlight runtime. 问题是,当测试在NUnit控制台中运行时,我相信它在CLR中运行,而不是在Silverlight运行时中运行。

We have successfully used NUnit and NCover with some Silverlight code, but then it's because the code we were testing was compatible with the full .NET CLR. 我们已经成功地将NUnit和NCover与一些Silverlight代码一起使用,但这是因为我们正在测试的代码与完整的.NET CLR兼容。

This is also a good article that describes how to unit test Silverlight with NUnit: http://chris.59north.com/post/Introduction-to-setting-up-automated-unit-testing-in-Silverlight-with-NUnit.aspx 这也是一篇很好的文章,描述了如何使用NUnit对Silverlight进行单元测试: http : //chris.59north.com/post/Introduction-to-setting-up-automated-unit-testing-in-Silverlight-with-NUnit。 aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM