abb*_*33f 5 c# nunit test-runner
使用SpecFlow Gherkin功能
解决方案以这样的方式设置我的解决方案
-测试项目
-功能
-步骤
-页面项目
-页面
我使用以下命令运行nUnit测试运行程序:
"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" ".\bin\Dev\Solution.dll"
并且我已将此代码添加到上述项目结构的步骤文件夹中。
using System;
using NUnit.Framework;
namespace TestsProject.StepDefinitions
{
/// <summary>
/// This class needs to be in the same namespace as the StepDefinitions
/// see: https://www.nunit.org/index.php?p=setupFixture&r=2.4.8
/// </summary>
[SetUpFixture]
public class NUnitSetupFixture
{
[SetUp]
public void RunBeforeAnyTests()
{
// this is not working
throw new Exception("This is never-ever being called.");
}
[TearDown]
public void RunAfterAnyTests()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?为什么[SetupFixture]在所有测试由nUnit开始之前不被调用?
使用OneTimeSetUp和OneTimeTearDown属性,因为SetUpFixture您使用的是 NUnit 3.0,而不是此处SetUp详细介绍的和TearDown属性。
using System;
using NUnit.Framework;
namespace TestsProject.StepDefinitions
{
[SetUpFixture]
public class NUnitSetupFixture
{
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
//throw new Exception("This is called.");
}
[OneTimeTearDown]
public void RunAfterAnyTests()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)