Loading NUnit project file (example.nunit) during Specflow feature execution

[亡魂溺海] 提交于 2019-12-08 06:01:55

问题


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 : Unable to locate fixture.

Command trying to run:

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

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.

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>

回答1:


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(){
      ..
   }
}

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

Note you can replace debug with release, if you compiled it with the release setting. I assume we use debug for now.

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>

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. Specify the relative path of the DLL file from the NUnit file
  2. Specify that path without placeholders
  3. Execute the test, using the NUnit file

Does this work for you?

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

  1. Create first an empty project with just a single unit test
  2. Run that test by executing nunit3-console.exe c:\absolutepath\to\my\project.dll
  3. If the above works, start creating the NUnit file and run it using the NUnit file and see if that works.
  4. Try specifying a configuration and using that configuration for the different environments.


来源:https://stackoverflow.com/questions/40877478/loading-nunit-project-file-example-nunit-during-specflow-feature-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!