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

StackOverflow https://stackoverflow.com/questions/3815946

  •  26-09-2019
  •  | 
  •  

我尝试将 Moles 与 NUnit 一起使用,但收到以下错误“Moles 需要测试才能成为仪表化过程”。我还在 Visual Studio 2008 中使用 Visual NUnit 来实现此功能。欢迎任何帮助。

有帮助吗?

解决方案

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

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

  2. 构建 NUnit Visual Studio (2008) 中的项目用于发布。

  3. 复制输出文件 Microsoft.Moles.NUnit.dllMicrosoft.Moles.NUnit.xml...\Moles\NUnit\bin\Release\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 你刚刚复制了。

  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()) block 在这种情况下也适用。

一旦发现一切正常,您可能会考虑将moles runner 作为 Visual Studio 中的外部工具运行。按照中的说明进行操作 使用 Visual Studio 中的 NUnit 控制台运行 Moles, ,如步骤 6 所示更新参数。

请注意,这是在 Windows 7 64 位计算机上进行的,带有 NUnit 2.5.9、Microsoft Pex 和 Moles (x86) 0.94.51006.1。考虑不同路径、版本等的实际文件夹。

其他提示

我使用痣版本0.94.51023.0。

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

[HostType("Moles")]

我也看到了,你可以添加[Moled]属性的测试方法,但没有提供给我,我没去成,为什么,假设它是旧的文档 - 这似乎是一个很大的用摩尔。

<强>更新:按摩尔数参考手册,第26,在测试方法MoledAttribute是去与NUnit的方式。必须注册的 Microsoft.Moles.NUnit.dll 组件使用Nunit通过其复制到NUnit的的仓/加载项文件夹。

然后,你将在[Moled]属性添加到测试方法。

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

否则,将添加一个使用块来包装的测试方法如下:

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

在除了添加[HOSTTYPE(“摩尔”)]属性,你需要包装与摩尔转轮测试运行。例如:

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

痣亚军很可能位于 C:\ Program Files文件\微软痣\ BIN 。有关使用方法,执行:

moles.runner.exe help

superjos拥有最正确的答案,并使用了“持续测试”的插件,你可以得到Visual Studio来通过与这个批处理文件NUnit的控制台亚军运行痣亚军:

@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

刚刚更新的路径到你的软件包的版本。这也可以使用,如果你有更新的时候从其他程序运行它。

可以不从Visual Studio中运行MS痣使用Nunit。您必须使用MSTest的(Visual Studio的单元测试)要做到这一点,或者你可以用痣从命令line.See运行NUnit的测试的参考手册

另一种可能:如果它适合你的需求,你可以使用加利奥自动化平台上运行各种测试框架(你的情况NUnit的和MSTest的)并排...

HTH! 托马斯

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top