Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xUnit framework: Equivalent of [TestFixtureSetUp] of NUnit in XUnit?

Tags:

nunit

xunit

People also ask

Are NUnit and xUnit the same?

NUnit creates a new instance of the test class and then runs all of the test methods from the same instance. Whereas xUnit.net creates a new instance of the test class for each of the test methods.

Is xUnit better than NUnit?

As far as NUnit vs. XUnit vs. MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.

What is IClassFixture in xUnit?

Important note: xUnit.net uses the presence of the interface IClassFixture<> to know that you want a class fixture to be created and cleaned up. It will do this whether you take the instance of the class as a constructor argument or not.

What is TestFixtureSetUp?

Whereas the TestFixtureSetUp is where the test fixture, the required initial state of the system before tests are run, is initialized. Follow this answer to receive notifications.


There is no direct equivalent of [TestFixtureSetUp] in XUnit, but you can achieve similar functionality. This page lays out the translation between NUnit and XUnit (as well as a couple other C#/.NET test frameworks). However, XUnit largely got rid of setups/teardowns (this article explains why that decision was made). Instead, you need the test suite to implement an interface called IUseFixture<T> which can initialize some data for the fixture.

You might also want to read this overview of XUnit, written from the perspective somebody coming from an NUnit/MbUnit background.