尝试将 Moles 与 NUnit 一起使用。获得“Moles 需要测试成为一个仪器化过程”

发布于 2024-09-25 03:42:22 字数 114 浏览 3 评论 0原文

我尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

独夜无伴 2024-10-02 03:42:22

为了让 Moles 能够与 NUnit 一起工作,我这样做了:

  1. 在 C:\Program Files (x86)\Microsoft Moles\Documentation\moles.samples.zip 处获取存档并解压Moles 解决方案文件夹。

  2. 在 Visual Studio (2008) 中构建 NUnit 项目以供发布。

  3. ...\Moles\NUnit\bin\ 复制输出文件 Microsoft.Moles.NUnit.dllMicrosoft.Moles.NUnit.xml发布\C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\。我怀疑这一步是重新编译 NUnit 插件,而不是使用来自下载的插件。安装是实际的解决点。

  4. 在 VS 测试项目中,确保添加对 C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\Microsoft.Moles.NUnit.dll 的引用< /code> 您刚刚复制的。

  5. 在 VS 测试类中,使用 [Moled] 属性标记测试方法(这需要 using Microsoft.Moles.Framework.NUnit)。作为替代方案,将其实现包装在 using (MolesContext.Create()) { ... } 块中(这将需要 using Microsoft.Moles.Framework)。

  6. 从命令行,使用以下命令通过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:

  1. Grab the archive at C:\Program Files (x86)\Microsoft Moles\Documentation\moles.samples.zip and extract the Moles solution folder.

  2. Build the NUnit project in Visual Studio (2008) for Release.

  3. Copy the output files Microsoft.Moles.NUnit.dll and Microsoft.Moles.NUnit.xml from ...\Moles\NUnit\bin\Release\ to C:\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.

  4. 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.

  5. In your VS test class, mark a test method with the [Moled] attribute (this will require an using Microsoft.Moles.Framework.NUnit). As an alternative, wrap its implementation within an using (MolesContext.Create()) { ... } block (this will require an using Microsoft.Moles.Framework).

  6. 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.

臻嫒无言 2024-10-02 03:42:22

我使用的是 Moles 版本 0.94.51023.0。

据我所知,您需要将以下属性添加到您的测试方法中。我正在使用 Visual Studio 测试框架,不确定它是否与 NUnit 等相同。等人。

[HostType("Moles")]

我还读到,您可以将 [Moled] 属性添加到测试方法中,但这对我来说不可用,并且我没有详细说明原因,假设它是旧文档 - 那里有看来跟鼹鼠有很多关系。

更新:根据《Moles 参考手册》第 14 页。 26、测试方法上的MoledAttribute是与NUnit走的路。您必须将 Microsoft.Moles.NUnit.dll 程序集复制到 NUnit bin/addins 文件夹,从而向 NUnit 注册。

然后,您可以将 [Moled] 属性添加到测试方法中。

[Test]
[Moled]
public void MyTest() {
  ...
}

否则,您将添加一个 using 块来包装测试方法,如下所示:

[Test]
public void MyTest() {
  using (MolesContext()) {
  ...
  }
}

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.

[HostType("Moles")]

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.

[Test]
[Moled]
public void MyTest() {
  ...
}

Otherwise, you would add a using block to wrap the test method as below:

[Test]
public void MyTest() {
  using (MolesContext()) {
  ...
  }
}
淡看悲欢离合 2024-10-02 03:42:22

除了添加 [HostType("Moles")] 属性之外,您还需要用 moles 运行程序包装测试运行程序。例如:

moles.runner.exe MyAssembly.dll /r:nunit-console.exe

Moles 运行程序可能位于 C:\Program Files\Microsoft Moles\bin 中。使用时,执行:

moles.runner.exe help

In addition to adding the [HostType("Moles")] attribute, you need to wrap the test runner with the moles runner. For example:

moles.runner.exe MyAssembly.dll /r:nunit-console.exe

The Moles runner is probably located in C:\Program Files\Microsoft Moles\bin. For usage, execute:

moles.runner.exe help
稚气少女 2024-10-02 03:42:22

superjos 有最正确的答案,使用“持续测试”插件,您可以让 Visual Studio 通过 NUnit 控制台运行程序使用此批处理文件运行 Moles 运行程序:

@echo off

rem Uses the Microsoft Moles runner and fires off the NUnit console runner so you can use Moles with NUnit.
rem This batch file is intended to be run from the Continuous Testing plugin in Visual Studio.
rem However, it can be used to run nunit tests from anyhere with Moles as long as the first parameter
rem is the assembly to be tested.  All other parameters are passed to NUnit.

set ASSEMBLY=%1
set MOLESPATH="c:\Program Files\Microsoft Moles\bin\moles.runner.exe"
set NUNITPATH="C:\Program Files\NUnit 2.5.10\bin\net-2.0\nunit-console.exe"
shift

if [%ASSEMBLY%]==[] goto HelpScreen
if [%1]==[] goto RunAlone
if [%2]==[] goto RunParams1 
if [%3]==[] goto RunParams2 
if [%4]==[] goto RunParams3 
if [%5]==[] goto RunParams4 
if [%6]==[] goto RunParams5 
if [%7]==[] goto RunParams6 
if [%8]==[] goto RunParams7 
if [%9]==[] goto RunParams8 
goto RunParams9
:HelpScreen
echo "The parameters are the same as NUnit Console runner with the exception that:
echo "   1) Only one assembly is supported and it must come first"
echo "   2) Only 9 extra parameters may be specified"
echo
%NUNITPATH% /?
exit 1
:RunAlone
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY%
goto ExitRunner
:RunParams1
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1
goto ExitRunner
:RunParams2
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2
goto ExitRunner
:RunParams3
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3
goto ExitRunner
:RunParams4
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4
goto ExitRunner
:RunParams5
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5
goto ExitRunner
:RunParams6
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6
goto ExitRunner
:RunParams7
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6 /args:%7
goto ExitRunner
:RunParams8
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6 /args:%7 /args:%8
goto ExitRunner
:RunParams9
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6 /args:%7 /args:%8 /args:%9
goto ExitRunner
:ExitRunner

只需更新软件包版本的路径即可。如果您有时间更新它,也可以使用它从其他程序运行它。

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:

@echo off

rem Uses the Microsoft Moles runner and fires off the NUnit console runner so you can use Moles with NUnit.
rem This batch file is intended to be run from the Continuous Testing plugin in Visual Studio.
rem However, it can be used to run nunit tests from anyhere with Moles as long as the first parameter
rem is the assembly to be tested.  All other parameters are passed to NUnit.

set ASSEMBLY=%1
set MOLESPATH="c:\Program Files\Microsoft Moles\bin\moles.runner.exe"
set NUNITPATH="C:\Program Files\NUnit 2.5.10\bin\net-2.0\nunit-console.exe"
shift

if [%ASSEMBLY%]==[] goto HelpScreen
if [%1]==[] goto RunAlone
if [%2]==[] goto RunParams1 
if [%3]==[] goto RunParams2 
if [%4]==[] goto RunParams3 
if [%5]==[] goto RunParams4 
if [%6]==[] goto RunParams5 
if [%7]==[] goto RunParams6 
if [%8]==[] goto RunParams7 
if [%9]==[] goto RunParams8 
goto RunParams9
:HelpScreen
echo "The parameters are the same as NUnit Console runner with the exception that:
echo "   1) Only one assembly is supported and it must come first"
echo "   2) Only 9 extra parameters may be specified"
echo
%NUNITPATH% /?
exit 1
:RunAlone
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY%
goto ExitRunner
:RunParams1
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1
goto ExitRunner
:RunParams2
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2
goto ExitRunner
:RunParams3
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3
goto ExitRunner
:RunParams4
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4
goto ExitRunner
:RunParams5
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5
goto ExitRunner
:RunParams6
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6
goto ExitRunner
:RunParams7
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6 /args:%7
goto ExitRunner
:RunParams8
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6 /args:%7 /args:%8
goto ExitRunner
:RunParams9
%MOLESPATH% /r:%NUNITPATH% %ASSEMBLY% /args:%1 /args:%2 /args:%3 /args:%4 /args:%5 /args:%6 /args:%7 /args:%8 /args:%9
goto ExitRunner
:ExitRunner

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.

难忘№最初的完美 2024-10-02 03:42:22

您无法在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文