本文介绍了在Specflow功能执行期间加载NUnit项目文件(example.nunit)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了启用环境配置,我在SpecFlow BDD框架中包含了一个NUnit项目(根据 ).但是,当我尝试从命令提示符加载它时,我收到了错误消息

To enable environment configuration, I included an NUnit project as part of the SpecFlow BDD framework (as per Pass parameters via command line to NUnit). But when I try to load it from the command prompt, I am getting the error message

试图运行的命令:

nunit-console-x86.exe example.nunit /config:CI /run:"xxxx.Features.abcdFeature" $dll_dir /result=$result_dir

该框架符合 不同步骤定义或类之间的SpecFlow和Selenium-Share数据 ,使用NUnit 2.6.4和SpecFlow 1.9.

The framework is as per SpecFlow and Selenium-Share data between different step definitions or classes,using NUnit 2.6.4 and SpecFlow 1.9.

我的NUnit项目文件.是否需要在上面的nunit.exe命令中传递.csproj文件或DLL文件?

My NUnit project file. Do we need to pass a .csproj file or DLL file in the nunit.exe command above?

<NUnitProject>
  <Settings activeconfig="Default" />
  <Config name="Default" configfile="App.CI.config">
    <assembly path="C:\FuncTest\{ProjectName}\{ProjectName}\bin\Debug\{ProjectName}.dll" />
  </Config>
  <Config name="CI" configfile="App.CI.config">
    <assembly path="C:\FuncTest\{ProjectName}\{ProjectName}\bin\Debug\{ProjectName}.dll" />
  </Config>
  <Config name="UAT" configfile="App.UAT.config">
    <assembly path="C:\FuncTest\{ProjectName}\{ProjectName}\bin\Debug\{ProjectName}.dll" />
  </Config>
</NUnitProject>

推荐答案

我假设您有一个项目,其中至少包含一个类似于以下内容的测试装置:

I assume that you have a project containing at least one test fixture which looks something like this:

[TestFixture]
public class MyFirstTestFixture{

   [Test]
   public void MyFirstTest(){
      ..
   }
}

因此,如果您的项目名为myfirstproj.csproj,其中包含此固定装置,则将生成以下文件myfirstproj/bin/debug/myfirstproj.dll.

So if you project is called myfirstproj.csproj, which contains this fixture, this will produce the following file myfirstproj/bin/debug/myfirstproj.dll.

现在,您将创建一个新的NUnit文件(与myfirstproj.csproj放在同一文件夹中),并像这样放置内容(我假设您将其命名为myfirstproj.nunit):

Now you create a new NUnit file (in the same folder as the myfirstproj.csproj) file and place the contents like this (I assume you call it myfirstproj.nunit):

<NUnitProject>
  <Settings activeconfig="local"/>
  <Config name="local" configfile="App.config">
    <assembly path="bin\Debug\myfirstproj.dll"/>
  </Config>
</NUnitProject>

现在,当您需要NUnit时,您可以像这样:

Now when you want NUnit you do it like this:

nunit3-console.exe myfirstproj.nunit /config:local

因此,您的设置和我的设置之间的区别:

So for the difference between your setup and mine:

  1. 从NUnit文件中指定DLL文件的相对路径
  2. 指定没有占位符的路径
  3. 使用NUnit文件执行测试

这对您有用吗?

如果您要调试它,我将使用以下步骤:

If you want to debug this, I would use this steps:

  1. 首先仅用一个单元测试创​​建一个空项目
  2. 通过执行nunit3-console.exe c:\ absolutepath \ to \ my \ project.dll来运行该测试
  3. 如果上述方法可行,则开始创建NUnit文件并使用NUnit文件运行它,看看是否可行.
  4. 尝试指定配置,并将该配置用于不同的环境.

这篇关于在Specflow功能执行期间加载NUnit项目文件(example.nunit)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:15