Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counterpart for NUnit attribute [SetUp()] in Visual Studio

I am "translating" a NUnit test to Visual Studios unit testing and I am wondering if the attribute [ClassInitialize()] in VS is equivalent to [SetUp()] in NUnit?

like image 250
Stefan Ahlm Avatar asked May 05 '10 09:05

Stefan Ahlm


People also ask

What is NUnit SetUp attribute?

SetUpAttribute (NUnit 2.0 / 2.5) This attribute is used inside a TestFixture to provide a common set of functions that are performed just before each test method is called. It is also used inside a SetUpFixture, where it provides the same functionality at the level of a namespace or assembly.

What is SetUp attribute?

The SetUp attribute is inherited from any base class. Therefore, if a base class has defined a SetUp method, that method will be called before each test method in the derived class. You may define a SetUp method in the base class and another in the derived class.

What does SetUp do in C#?

A SetUp method runs before each test method within a test class so is used to set up common code required for each method - this could be providing stubs/fakes/mocks for any dependencies that the System Under Test requires, as well as perhaps instantiating an instance of the System Under Test.


1 Answers

[SetUp] corresponds to [TestInitialize]

[TestFixtureSetUp] corresponds to [ClassInitialize]

Here's the full picture.

like image 152
Darin Dimitrov Avatar answered Nov 15 '22 04:11

Darin Dimitrov