问题
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:
- Specify the relative path of the DLL file from the NUnit file
- Specify that path without placeholders
- Execute the test, using the NUnit file
Does this work for you?
If you want to debug this, I would use this steps:
- Create first an empty project with just a single unit test
- Run that test by executing nunit3-console.exe c:\absolutepath\to\my\project.dll
- If the above works, start creating the NUnit file and run it using the NUnit file and see if that works.
- 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