用于 xamarin android 的模拟框架 [英] Mocking framework for use with xamarin android

查看:15
本文介绍了用于 xamarin android 的模拟框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一个适用于 Xamarin Android 的模拟框架.到目前为止,我已经尝试过 Rhino Mocks 和 Moq,但两者都依赖于 Xamarin 似乎不支持的 System.Web.dll.我已经将 System.Web.Services 引用包含到我的项目中,但没有运气.

I am trying to find a mocking framework that works with Xamarin Android. So far I have tried Rhino Mocks and Moq but both depend on System.Web.dll which does not seem to be supported by Xamarin. I have included the System.Web.Services reference to my project with no luck.

所以我的问题是哪些模拟框架与 Xamarin 项目兼容?这只是为了简单的模拟,甚至不是像活动这样的特定 android 类,尽管可以将两者结合起来会是最好的.

So my question is what mocking frameworks out there are compatible with Xamarin projects? This is just for simple mocking not even specific android classes like activities, although one that could combine both would be best.

推荐答案

从我观察到的情况来看,确实没有任何模拟框架可以很好地与 Xamarin 配合使用.在iOS端,这主要是由于Apple强加的代码生成限制而无法使用Reflection.Emit.我知道您使用的是 Android,因此该限制不适用于您.但是,会出现其他限制,就像您在 RhinoMocks 中发现的那样.我最喜欢的模拟框架是 Moq,但我不能将它与 Xamarin 一起使用,因为某些配置命名空间在 .NET 中实现,但在 Mono 中没有实现.

From what I've observed, there really is no mocking frameworks that work well with Xamarin. On the iOS side, this is mainly due to the inability to use Reflection.Emit because of the code generation restriction imposed by Apple. I realize you're on Android, so that restriction does not apply to you. However, other restrictions arise, like you've found with RhinoMocks. My favorite mocking framework is Moq, but I can't use it with Xamarin because of some of the configuration namespaces that are implemented in .NET, but not in Mono.

所以,最好的办法就是手动模拟.我知道这不是你想听到的答案,但这似乎是共识.

So, your best bet is just manual mocks. I know that's not the answer you want to hear, but it seems to be the consensus.

这篇关于用于 xamarin android 的模拟框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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