在 Specflow 功能执行期间加载 NUnit 项目文件 (example.nunit)
Loading NUnit project file (example.nunit) during Specflow feature execution
为了启用环境配置,我包含了一个 NUnit 项目作为 SpecFlow BDD 框架的一部分(根据 Pass parameters via command line to NUnit)。但是当我尝试从命令提示符加载它时,我收到错误消息
.\nunit-console-x86.exe : Unable to locate fixture.
命令试图 运行:
nunit-console-x86.exe example.nunit /config:CI /run:"xxxx.Features.abcdFeature" $dll_dir /result=$result_dir
框架按照 ,
使用 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>
我假设您的项目至少包含一个如下所示的测试装置:
[TestFixture]
public class MyFirstTestFixture{
[Test]
public void MyFirstTest(){
..
}
}
因此,如果您的项目名为 myfirstproj.csproj,其中包含此固定装置,则会生成以下文件 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.
现在你创建一个新的 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
所以对于你的设置和我的设置之间的差异:
- 从NUnit文件指定DLL文件的相对路径
- 指定不带占位符的路径
- 执行测试,使用 NUnit 文件
这对你有用吗?
如果你想调试这个,我会使用这个步骤:
- 首先创建一个只有一个单元测试的空项目
- 运行 通过执行 nunit3-console.exe c:\absolutepath\to\my\project.dll
进行测试
- 如果上述方法有效,请开始创建 NUnit 文件并运行它使用 NUnit 文件并查看是否有效。
- 尝试指定配置并将该配置用于不同的环境。
为了启用环境配置,我包含了一个 NUnit 项目作为 SpecFlow BDD 框架的一部分(根据 Pass parameters via command line to NUnit)。但是当我尝试从命令提示符加载它时,我收到错误消息
.\nunit-console-x86.exe : Unable to locate fixture.
命令试图 运行:
nunit-console-x86.exe example.nunit /config:CI /run:"xxxx.Features.abcdFeature" $dll_dir /result=$result_dir
框架按照
我的 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>
我假设您的项目至少包含一个如下所示的测试装置:
[TestFixture]
public class MyFirstTestFixture{
[Test]
public void MyFirstTest(){
..
}
}
因此,如果您的项目名为 myfirstproj.csproj,其中包含此固定装置,则会生成以下文件 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.
现在你创建一个新的 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
所以对于你的设置和我的设置之间的差异:
- 从NUnit文件指定DLL文件的相对路径
- 指定不带占位符的路径
- 执行测试,使用 NUnit 文件
这对你有用吗?
如果你想调试这个,我会使用这个步骤:
- 首先创建一个只有一个单元测试的空项目
- 运行 通过执行 nunit3-console.exe c:\absolutepath\to\my\project.dll 进行测试
- 如果上述方法有效,请开始创建 NUnit 文件并运行它使用 NUnit 文件并查看是否有效。
- 尝试指定配置并将该配置用于不同的环境。