【问题标题】:Loading NUnit project file (example.nunit) during Specflow feature execution在 Specflow 功能执行期间加载 NUnit 项目文件 (example.nunit)
【发布时间】:2017-04-14 03:12:26
【问题描述】:

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

.\nunit-console-x86.exe : 无法定位夹具。

尝试运行的命令:

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

框架按照SpecFlow and Selenium-Share data between different step definitions or classes, 使用 NUnit 2.6.4 和 SpecFlow 1.9。

我的 NUnit 项目文件。我们需要在上面的 nunit.exe 命令中传递一个 .csproj 文件还是 DLL 文件?

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

【问题讨论】:

  • 你能发布你的 nconfig 文件吗?
  • @MaartenKieft 根据要求,编辑了查询。添加了 nunit 文件内容

标签: selenium-webdriver nunit specflow


【解决方案1】:

我假设您的项目至少包含一个如下所示的测试夹具:

[TestFixture]
public class MyFirstTestFixture{

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

因此,如果您的项目名为 myfirstproj.csproj,其中包含此夹具,则会生成以下文件 myfirstproj/bin/debug/myfirstproj.dll。

请注意,如果您使用发布设置编译它,您可以将调试替换为发布。我假设我们现在使用调试。

现在你创建一个新的 NUnit 文件(在与 myfirstproj.csproj 相同的文件夹中)文件并像这样放置内容(我假设你称之为 myfirstproj.nunit):

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

现在当你想要 NUnit 时,你可以这样做:

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

所以对于您的设置和我的设置之间的差异:

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

这对你有用吗?

如果你想调试这个,我会使用这个步骤:

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

【讨论】:

  • -谢谢,那行得通。我在控制台中传递 nunit 项目文件来运行测试。只需要传递 .nunit 文件。但是,如何在发布模式下运行相同的文件?
  • 如果你愿意,你可以创建 2 个 nunit 文件。但我总是使用发布版本,因为我在本地使用来自 Visual Studio 的测试资源管理器或来自 resharper 的 nunit 测试器。我只在构建服务器中使用 nunit 控制台:)
猜你喜欢
  • 1970-01-01
  • 2020-11-10
  • 1970-01-01
  • 2020-01-05
  • 2011-06-17
  • 2017-12-27
  • 2017-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多