Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference if TestFixture attribute is used or not

I cant see any difference in behaviour for class that has TestFixture attribute and not. All TearDown and SetUp are working in the same way. Is there any reason except semantics for this attribute usage?

like image 709
Sly Avatar asked Dec 06 '11 13:12

Sly


People also ask

What is the use of TestFixture attribute?

The [TestFixture] attribute at the beginning indicates that this class is a test fixture so that NUnit can identify it as a runnable test class. Similarly NUnit uses attributes to indicate various properties of classes/methods. Then you see two methods tagged [SetUp] and [TearDown].

Is TestFixture needed?

The TestFixture attribute is required however for parameterized or generic test fixture because in that case you also specify additional information through the attribute (parameters/concrete types).

What is NUnit explain NUnit test and test fixture?

The [TestFixture] attribute denotes a class that contains unit tests. The [Test] attribute indicates a method is a test method. Save this file and execute dotnet test to build the tests and the class library and then run the tests. The NUnit test runner contains the program entry point to run your tests.

What is a unit test fixture?

A test fixture is a fixed state of a set of objects used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.


2 Answers

Is purely a convenience, beginning with NUnit 2.5, if a class satisfies the conditions to be a test fixture and specifies at least a method marked with Test, TestCase or TestCaseSource than that class is treated as a test fixture.

The TestFixture attribute is required however for parameterized or generic test fixture because in that case you also specify additional information through the attribute (parameters/concrete types).

More information about the specific requirements is available at TextFixtureAttribute (NUnit 3 Documentation) and TestFixtureAttribute (NUnit 2.0 / 2.5)

like image 180
João Angelo Avatar answered Sep 19 '22 06:09

João Angelo


If you use [TestFixture] you have to put up with that voice in the back of your head saying "Hmm, this is a test class, not really a test fixture" and wonder how they got this annotation wrong.

See Why testFixture instead of testClass.

like image 40
ybakos Avatar answered Sep 22 '22 06:09

ybakos