NUnit SetupFixture class in C # not called when running tests
My solution is configured using SpecFlow Gherkin features
Solution
- Test Design
- Features | - Steps
- Page Design
- Pages
I run the nUnit test runner with the following command:
"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" ".\bin\Dev\Solution.dll"
And I added this code to the steps folder of the project structure above.
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()
{
}
}
}
What am I doing wrong? Why is the call being [SetupFixture]
called before all tests start with nUnit?
source to share
Use attributes for OneTimeSetUp
and OneTimeTearDown
for SetUpFixture
as you are using NUnit 3.0 attributes instead of SetUp
and TearDown
as verbose.
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()
{
}
}
}
source to share