尝试将 Moles 与 NUnit 一起使用。获得“Moles 需要测试成为一个仪器化过程”
我尝试将 Moles 与 NUnit 一起使用,但收到以下错误“Moles 需要测试才能成为仪表化过程”。我还在 Visual Studio 2008 中使用 Visual NUnit 来实现此功能。欢迎任何帮助。
I am trying to use moles with NUnit and am getting the following error "Moles requires tests to be an instrumented process". I am also using Visual NUnit within Visual Studio 2008 to get this working. Any help is welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为了让 Moles 能够与 NUnit 一起工作,我这样做了:
在 C:\Program Files (x86)\Microsoft Moles\Documentation\moles.samples.zip 处获取存档并解压
Moles
解决方案文件夹。在 Visual Studio (2008) 中构建
NUnit
项目以供发布。从
...\Moles\NUnit\bin\ 复制输出文件
到Microsoft.Moles.NUnit.dll
和Microsoft.Moles.NUnit.xml
发布\C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\
。我怀疑这一步是重新编译 NUnit 插件,而不是使用来自下载的插件。安装是实际的解决点。在 VS 测试项目中,确保添加对 C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\Microsoft.Moles.NUnit.dll 的引用< /code> 您刚刚复制的。
在 VS 测试类中,使用
[Moled]
属性标记测试方法(这需要using Microsoft.Moles.Framework.NUnit
)。作为替代方案,将其实现包装在using (MolesContext.Create()) { ... }
块中(这将需要using Microsoft.Moles.Framework
)。从命令行,使用以下命令通过moles运行程序调用NUnit测试运行程序:
"C:\Program Files (x86)\Microsoft Moles\bin\moles.runner.exe" "path\to\your \test\ assembly.dll" /r:"C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\nunit-console.exe" /x86 /args:"/domain=None"
我发现 [Moled] 属性不适用于 [TestCase(...)],它会让您回到未检测的错误场景。相反,
using (MolesContext.Create())
块在这种情况下也适用。一旦发现一切正常,您可能会考虑将moles runner 作为 Visual Studio 中的外部工具运行。遵循从 Visual Studio 中使用 NUnit 控制台运行 Moles 中的说明,按照步骤 6 更新参数。
请注意,这是在 Windows 7 64 位计算机上进行的,配有 NUnit 2.5.9、Microsoft Pex 和 Moles (x86) 0.94.51006.1。考虑不同路径、版本等的实际文件夹。
This is what I did in order to make Moles work with NUnit:
Grab the archive at
C:\Program Files (x86)\Microsoft Moles\Documentation\moles.samples.zip
and extract theMoles
solution folder.Build the
NUnit
project in Visual Studio (2008) for Release.Copy the output files
Microsoft.Moles.NUnit.dll
andMicrosoft.Moles.NUnit.xml
from...\Moles\NUnit\bin\Release\
toC:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\
. I suspect that this step of re-compiling the NUnit addin instead of using the one coming from the download & install was the actual solving point.In your VS test project, make sure you add a reference to the
C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\Microsoft.Moles.NUnit.dll
you just copied.In your VS test class, mark a test method with the
[Moled]
attribute (this will require anusing Microsoft.Moles.Framework.NUnit
). As an alternative, wrap its implementation within anusing (MolesContext.Create()) { ... }
block (this will require anusing Microsoft.Moles.Framework
).From the command line, invoke NUnit test runner through the moles runner with the following:
"C:\Program Files (x86)\Microsoft Moles\bin\moles.runner.exe" "path\to\your\test\assembly.dll" /r:"C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\nunit-console.exe" /x86 /args:"/domain=None"
I found that [Moled] attribute does not work with [TestCase(...)] and it brings you back to the uninstrumented error scenario. Instead the
using (MolesContext.Create())
block works in that case too.Once you find that everything works, you might consider running moles runner as an external tool within Visual Studio. Follows instructions in Running Moles using NUnit Console from Visual Studio, updating the arguments as in step 6.
Please note that this was on a Windows 7 64bit machine, with NUnit 2.5.9, Microsoft Pex and Moles (x86) 0.94.51006.1. Consider your actual folders for different paths, versions, etc.
我使用的是 Moles 版本 0.94.51023.0。
据我所知,您需要将以下属性添加到您的测试方法中。我正在使用 Visual Studio 测试框架,不确定它是否与 NUnit 等相同。等人。
我还读到,您可以将
[Moled]
属性添加到测试方法中,但这对我来说不可用,并且我没有详细说明原因,假设它是旧文档 - 那里有看来跟鼹鼠有很多关系。更新:根据《Moles 参考手册》第 14 页。 26、测试方法上的MoledAttribute是与NUnit走的路。您必须将 Microsoft.Moles.NUnit.dll 程序集复制到 NUnit bin/addins 文件夹,从而向 NUnit 注册。
然后,您可以将
[Moled]
属性添加到测试方法中。否则,您将添加一个 using 块来包装测试方法,如下所示:
I'm using Moles version 0.94.51023.0.
As far as I'm aware, you need to add the below attribute to your test method. I'm using the Visual Studio testing framework, not sure if it's the same with NUnit, et. al.
I've also read that you can add the
[Moled]
attribute to the test method, but that was not available to me, and I didn't go into why, assuming it's old documentation - which there seems to be a lot of with Moles.Update: As per the Moles Reference Manual, pg. 26, the MoledAttribute on the test method is the way to go with NUnit. You must register the Microsoft.Moles.NUnit.dll assembly with NUnit by copying it to the NUnit bin/addins folder.
Then you would add the
[Moled]
attribute to the test method.Otherwise, you would add a using block to wrap the test method as below:
除了添加 [HostType("Moles")] 属性之外,您还需要用 moles 运行程序包装测试运行程序。例如:
Moles 运行程序可能位于 C:\Program Files\Microsoft Moles\bin 中。使用时,执行:
In addition to adding the [HostType("Moles")] attribute, you need to wrap the test runner with the moles runner. For example:
The Moles runner is probably located in C:\Program Files\Microsoft Moles\bin. For usage, execute:
superjos 有最正确的答案,使用“持续测试”插件,您可以让 Visual Studio 通过 NUnit 控制台运行程序使用此批处理文件运行 Moles 运行程序:
只需更新软件包版本的路径即可。如果您有时间更新它,也可以使用它从其他程序运行它。
superjos has the most correct answer and using the "Continuous Testing" addin you can get Visual Studio to run the Moles runner through the NUnit console runner with this batch file:
Just update the paths to your version of the software packages. This can also be used to run it from other programs if you have the time to update it.
您无法在 Visual Studio 中使用 NUnit 运行 MS Moles。您必须使用 MSTest(Visual Studio 单元测试)来执行此操作,或者可以从命令行使用 Moles 运行 NUnit 测试。请参阅 参考手册。
一个可能的替代方案:如果它适合您的需求,您可以使用 Gallio 自动化平台来运行各种测试框架(在你的情况下,NUnit 和 MSTest)并排......
HTH!
托马斯
You can't run MS Moles with NUnit from within Visual Studio. You must either use MSTest (Visual Studio Unit Tests) to do that or you can run your NUnit tests with Moles from the command line.See the reference manual.
A possible alternative: If it fits your needs, you may use the Gallio automation platform to run all kinds of test frameworks (in your case NUnit and MSTest) side by side...
HTH!
Thomas