Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does NUnit support the concept of an Assembly Teardown?

Does NUnit support the concept of an Assembly Teardown similar to the Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute that can be applied to a static method?

This would be run after all the tests within the assembly have completed. I am currently using NUnit 2.6.0.

like image 811
Rodney S. Foley Avatar asked Jan 11 '13 23:01

Rodney S. Foley


2 Answers

It turns out this functionality does exist in NUnit it is just not very obvious or intuitive.

According to Charlie Poole in the feature request I made for this functionality here, he states the following will work, which is a direct quote from him.

Decorate a class outside of any namespace with [SetUpFixture]. Decorate a method of that class with [TearDown]. If you like, decorate another with [SetUp].

Differences from what you are asking for:

  1. The name makes it a little unobvious in this usage.

  2. NUnit allows any number of these and calls them all, without any guarantee of ordering. This is by design.

  3. It can be applied to a static or instance method. If it's an instance method, the class must have a default constructor and it will be created with a lifespan of the entire test run. This is also by design.

Now this is not pretty but it should achieve the same functionality, and maybe he will make it a little cleaner in 3.0. :)

like image 161
Rodney S. Foley Avatar answered Nov 18 '22 10:11

Rodney S. Foley


There is no such concept in NUnit. But you can apply TestFixtureTearDownAttribute to method to free resources obtained by TestFixture.

like image 1
Sergey Berezovskiy Avatar answered Nov 18 '22 10:11

Sergey Berezovskiy