Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
I haven't seen much information online comparing the similarities and differences between the Nunit and MSTest Frameworks. Here I will define the similarities and some of the differences. If there is anything else which you come upon, please do add it to the comments.
MSTest Attribute |
NUnit Attribute |
Purpose |
[TestMethod] |
[Test] |
Indentifies of an individual unit test |
[TestClass] |
[TestFixture] |
Identifies of a group of unit tests, all Tests, and Initializations/Clean Ups must appear after this declaration |
[ClassInitialize] |
[TestFixtureSetUp] |
Identifies a method which should be called a single time prior to executing any test in the Test Class/Test Fixture |
[ClassCleanup] |
[TestFixtureTearDown] |
Identifies a method in to be called a single time following the execution of the last test in a TestClass/TestFixture |
[TestInitialize] |
[SetUp] |
Identifies a method to be executed each time before a TestMethod/Test is executed |
[TestCleanUp] |
[TearDown] |
Identifies a method to be executed each time after a TestMethod/Test has executed |
[AssemblyInitialize] |
N/A |
Identifies a method to be called a single time upon before running any tests in a Test Assembly |
[AssemblyCleanUp] |
N/A |
Identifies a method to be called a single time upon after running all tests in a Test Assembly |
The order of execution is similar in both frameworks, but there are some differences between the two:
I should also mentioned that in MsTest, TestContext exists for passing information about the test run. There is no equivalent in Nunit tests. This can serve as a handy tool for pulling information from datasources on the disk to the unit tests, as well as other uses. More can be read about it here.
Anonymous
March 27, 2007
Are there plans to add support for NUnit's Category attribute?
http://nunit.org/index.php?p=category&r=2.4
Buck
Anonymous
March 27, 2007
Naysawn Naderi has a matrix of attributes between NUnit and MSTest . To balance MbUnit in this matrix,
Anonymous
April 01, 2007
I just came across a great blog entry that compares the different attributes in both MSTest and NUnit.
Anonymous
April 01, 2007
The comment has been removed
Anonymous
April 04, 2007
From Buck: "Are there plans to add support for NUnit's Category attribute?"
We have been discussing this. I think that it would be quite beneficial. Do you prefer it to the test lists that we have implemented?
Anonymous
May 11, 2007
The comment has been removed
Anonymous
May 11, 2007
Now, I'm not claiming to be anything remotely close to a Test-Driven Development expert - heck, I only
Anonymous
July 28, 2007
I think that [AssemblyInitialize] and
[AssemblyCleanUp] in MSTest correspond to
[SetUp] and [TearDown] in the [SetUpFixture] of NUnit.
Anonymous
September 18, 2007
The comment has been removed
Anonymous
September 18, 2007
The comment has been removed
Anonymous
October 29, 2007
MBUnit's TestSuiteFixture is a TestClass than can be populated at runtime (e.g. by fetching data from files in folders). Only way I know of doing that with MSTest is by adding an MSBuild task that runs before project compilation, that generates source code (i.e. alla CodeSmith), that will later be compiled by CSC and finally detected as a test by MSTest.
Anonymous
December 17, 2009
Some major differences in MSTest compared to NUnit is that:
Anonymous
August 28, 2010
Hi. I'm wondering about why support for inheritance of test classes is still not supported?? I wrote a question about it on stackoverflow.com, perhaps somebody reads this and can answer it:
stackoverflow.com/.../is-defining-testmethods-in-test-base-classes-not-supported-by-mstest
Thanks
Anonymous
August 11, 2011
This might help:
Unit testing frameworks: MSTest v/s NUnit @ http://santats.blogspot.com/
Anonymous
January 21, 2013
thanks,Actually [TestCleanUp] should be [TestCleanup] and
[AssemblyCleanUp] should be [AssemblyCleanup].
Anonymous
July 30, 2013
Why One Sided review?
MSTest still don't have "TestCase" attribute which NUnit has, it makes calling the same test method several times with different parameters, very easy.
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in