有人让痣正常工作了吗?
我试图找到关于如何使用鼹鼠隔离框架的一致描述,但在这个主题上没有找到太多。 到目前为止,我做了以下操作:
- 从此处下载鼹鼠( x86 版本)。
- 安装它。
- 这里家伙描述了如何使用它与自定义库。所以我为我自己的库添加了摩尔组件。重建后,程序集出现在参考文献中。
- 然后我尝试添加使用 .Moles 命名空间并构建项目,但由于出现一堆错误而失败。 MDateTime 的示例也不起作用。 MDateTime 只是没有任何方法。
- 考虑到这是第五次失败的尝试让它工作,我从系统中卸载了它。
那么问题来了:痣对任何人都有效吗?如果是的话,你是怎么到达那里的? 我还应该安装 pex 才能使其正常工作吗? 如果我想通过 msbuild 脚本在构建服务器上使用它怎么办?我看到他们提到了对 msbuild 的支持,但是有人真正有过从 msbuild 使用它的经验吗?
对我来说,在严肃的开发过程中使用它看起来非常原始。 也许有人有其他意见?
谢谢。
I was trying to find a consistent description on how to use moles isolation framework but haven't found much on this topic.
So far i did the following:
- Download moles from here (x86 version).
- Install it.
- Here guy describes how to use it with custom library. So i added moles assembly for my own library. After rebuild the assembly appeared in references.
- Then i tried to add using of .Moles namespace and build the project but it failed with bunch of errors. Example with MDateTime didn't work either. MDateTime just didn't have any method.
- Considering that was 5th failed attempt to get it work i uninstalled it from the system.
So the question: does moles work for anybody at all? If yes how did you get there?
Should i also install pex to make it work?
What if i want to use it on build server from msbuild script? I saw they mentioned support of msbuild, but has anyone real experience with using it from msbuild?
For me it looks very raw to be used in serious development process.
Maybe someone has another opinion?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,效果很好。我假设您正在安装 v0.94.51023.0。为了让 Moles 正常工作,您必须做一些事情,以设置测试类。这些很快就会成为第二天性——别担心!
您必须为您希望使用 Moles 的每个组件创建一个“模制组件”:
a.右键单击解决方案资源管理器的“引用”节点中的程序集,然后选择“添加 Moles 程序集”。
b.如果您希望摩尔一个 .NET Framework 程序集,请右键单击“引用”节点,然后选择“为 mscorlib 添加摩尔程序集”。
在.CS文件中引用Microsoft.Moles.Framework程序集:
using Microsoft.Moles.Framework;
构建项目。这会导致将适当的 Moles 框架引用添加到项目中。正如 @Lara 所评论的,如果不添加引用,第 3 步将会失败。
.CS 文件中的参考模制装配体:
using MyNamespace.Moles;
通过 [HostType("Moles"] 属性装饰使用 Moled 类型的测试方法
[HostType("Moles")]
识别整个程序集或单个程序集通过使用程序集属性,在 .CS 文件中使用的类型:
使用 MyNameSpace.MyAssemblyName.Moles;
[程序集:MoledAssemblyType("MyNameSpace.MyAssemblyName")]
[程序集:MoledType(typeof(MyNameSpace.MyAssemblyName.MyClass))]
编译测试项目时,Moles 会复制“moled”程序集,然后将迂回注入到副本中。模块化程序集和类型的命名空间附加有“.Moles”。因此,“MyNameSpace.MyAssembly”变为“MyNameSpace.MyAssembly.Moles”。我相信您也熟悉模制组件类型名称的“S”和“M”前缀。如果没有,请参阅Moles 参考手册。
Yes, it works fine. I assume you're installing v0.94.51023.0. For Moles to function properly, you must do a few things, to set up the test class. These quickly become second nature -- don't worry!
You must create a "moled assembly", for each assembly against which you wish to use Moles:
a. Right-click an assembly in the "References" node of the Solution Explorer, and then select "Add Moles Assembly".
b. If you wish to mole a .NET Framework assembly, right-click the References node, and then select "Add Moles Assembly for mscorlib'".
Reference the Microsoft.Moles.Framework assembly in the .CS file:
using Microsoft.Moles.Framework;
Build the project. This causes the appropriate Moles framework references to be added to the project. As @Lara commented, step 3 will fail, without adding the references.
Reference moled assemblies in the .CS file:
using MyNamespace.Moles;
Decorate test methods that use Moled types with the [HostType("Moles"] attribute
[HostType("Moles")]
Identify either an entire assembly or individual types that are used in the .CS file, by using the assembly attributes:
using MyNameSpace.MyAssemblyName.Moles;
[assembly: MoledAssemblyType("MyNameSpace.MyAssemblyName")]
[assembly: MoledType(typeof(MyNameSpace.MyAssemblyName.MyClass))]
When the test project is compiled, Moles copies the "moled" assemblies, and then injects detours into the copy. The namespace of moled assemblies and types are appended with ".Moles". Therefore, "MyNameSpace.MyAssembly" becomes "MyNameSpace.MyAssembly.Moles". I'm sure you are also familiar with the "S" and "M" prefixes to the type names of moled assemblies. If not, please refer to the Moles Reference Manual.
它对我来说效果很好,我也刚刚用 MDateTime 尝试过。只需确保在 using 中放置正确的命名空间或直接在代码中使用 System.Moles.MDateTime 即可。然后,Intellisense 应该为您提供所有方法和属性,以便根据需要进行设置。
正如您已经说过的,您在添加摩尔组件后重建了项目,这应该不再是问题了。
对于某些类(我现在不太确定,也许那些不属于 mscorlib 的类?)我还必须将其添加
到我的单元测试类的顶部(在命名空间之上),并且也
作为我的测试的属性方法,但这对于 MDateTime 来说不是必需的。
您是否下载了最新版本并将VS2010更新到最新的SP?
希望其中一些有所帮助...
G.
It works quite fine for me, and I just tried it out with MDateTime as well. Just make sure that you either put the correct namespace in your using or use System.Moles.MDateTime directly in your code. Intellisense should then give you all methods and properties to set it up as desired.
As you've already said that you rebuilt your project after adding the moles assembly, this shouldn't be the problem anymore.
For some classes (I'm not quite sure right now, maybe those that are not part of mscorlib?) I also had to add the
to the top of my unit test class (above the namespace), and also
as attribute to my test methods, but this is not necessary for MDateTime.
Did you download the most recent version and also update your VS2010 to the latest SP?
Hope some of this helps...
G.