[英]nUnit SetupFixture class in C# not being called when tests are run
使用SpecFlow Gherkin功能,我的解決方案就像這樣設置
解
- 測試項目
- 特征
- 腳步
- 頁面項目
- 頁面
我使用如下命令運行nUnit測試運行器:
"C:\\Program Files (x86)\\NUnit.org\\nunit-console\\nunit3-console.exe" ".\\bin\\Dev\\Solution.dll"
我已將此代碼添加到上面項目結構的steps文件夾中。
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()
{
}
}
}
我究竟做錯了什么? 在nUnit開始所有測試之前,為什么不調用[SetupFixture]
?
使用SetUpFixture
的OneTimeSetUp
和OneTimeTearDown
屬性,因為您使用的是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()
{
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.