开发者

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

What is xUnit's equivalent of NUnit's [TestFixtureSetUp]?

We have explored and found that IUseFixture<T> is the equivalent of [TestFixtureSetUp], but it's not working as expected.

As we have explored (in case开发者_C百科 of NUnit), we found that [TestFixtureSetUp] marked methods for code to be executed only once before all test in the fixture have been run. In xUnit, the equivalent of [TestFixtureSetUp] is IUseFixture<T> as we have explored, but during testing, we found that the SetFixture method of IUseFixture is being called before every test (not only once for all methods).

Please let us know how can we achieve the above in xUnit. Also correct us if we are misunderstanding something. Thanks.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜