NUnit vs. MsTest: NUnit wins for Unit Testing.

My blog has moved. You can view this post at the following address: http://www.osherove.com/blog/2010/3/5/nunit-vs-mstest-nunit-wins-for-unit-testing.html
Published Friday, March 05, 2010 6:19 PM by RoyOsherove
Filed under:

Comments

Friday, March 05, 2010 7:20 PM by Jamie Cansdale

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

I've been working with MSTest a lot recently, adding support for the VS 2008 and 2010 flavours of MSTest to TestDriven.Net 3.0. There are some quirks and differences between the VS 2008 and VS 2010 versions that I've had to deal with.

1) This thing you mention about ExpectedException isn't actually a bug, it's more a badly named parameter. They've renamed it from 'message' to 'noExceptionMessage' in VS 2010. It's a message that will be displayed if no exception is thrown. For example:

[TestMethod, ExpectedException(typeof(ArgumentNullException),

  "CreateDomain shouldn't accept accept a null friendly name")]

public void CreateDomain_Null_ThrowsArgumentNullException()

{

  AppDomain.CreateDomain(null);

}

2) The VS 2010 version of MSTest now supports test fixtures that inherit from an abstract base class (that contains tests).

3) You can force MSTest for VS 2010 to execute in a 64-bit process using a setting under 'Local.testsettings > Hosts'.

If you use MSTest much, you should find the MSTest support in TestDriven.Net 3.0 Beta 2 is fast and pretty comprehensive. It now even supports data driven tests. :)

Friday, March 05, 2010 7:35 PM by yaronn01

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

I love NUnit, but unless I missed something there is not test runner fully integrated in VS. Even the Resharper runner still does not support all of the new attributes.

Friday, March 05, 2010 8:04 PM by Ryan Rivest

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

Hi Roy,

I may have misunderstood you mean by abstract test fixture, but if I understand correctly, I have used them with MSTest.

MSTest does not allow you to decorate the abstract fixture with the TestClassAttribute, but if you have methods decorated with the TestMethodAttribute, those tests will be inherited by the derived fixture.  So for example, if you had 5 tests in the abstract fixture, when you run the tests in your derived fixture, it will execute those 5 abstract test methods additionally.

Does NUnit handle this scenario differently?

Saturday, March 06, 2010 3:23 AM by Vagif Abillov

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

Roy,

For many developers MsTest has one attractive feature that outweight its weakenesses: it's runner is built-in into Visual Studio. Recently I read in Ben Hall's book about testing ASP.NET applications that VS 2010 test runner can be used to execute NUnit test. If this is true, this can make a lot of people start switching to NUnit or at least make beginners choose NUnit. But was not able to find anything about this. Do you know if there are such changes in VS 2010 test runner so it can now be configured to run tests with NUnit syntax (I guess TestCases will still be a problem)?

Saturday, March 06, 2010 3:44 AM by Vagif Abillov

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

Well, actually I received an answer to my question from Microsoft: social.msdn.microsoft.com/.../92da13df-0c4f-4212-be3b-cf1a9795a6ac

Saturday, March 06, 2010 1:06 PM by svdeursen

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

Just like Ryan I use abstract base classes in MSTest. I'm interested what you exactly mean.

Here's an example of what I use with MSTest:

public abstract class IntegrationTestBase

{

   private TransactionScope scope;

   [TestInitialize]

   public void TestInitialize()

   {

       scope = new TransactionScope();

   }

   [TestCleanup]

   public void TestCleanup()

   {

       scope.Dispose();

   }

}

[TestClass]

public class IntegrationTest : IntegrationTestBase

{

   [TestMethod]

   public void TestThatRunsInTransactionScope()

   {

       // This test runs in the context of the TransactionScope!

   }

}

Cheers

Saturday, March 06, 2010 3:24 PM by Vagif Abilov's blog on .NET

# NUnitForVS: integrating NUnit tests into Visual Studio

Roy Osherove listed advantages of NUnit over MsTest but also mentioned one MsTest’s strength that can

Saturday, March 06, 2010 3:26 PM by Euan Garden

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

I pointed out on stackoverflow that a bunch of your information is out of date as of 2010. Jamie has already pointed some of that out above

Monday, March 08, 2010 7:19 AM by Bjoern Rochel

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

Regarding the abstract classes for test fixtures:

There's a slightly different behavior in MSTest depending on where it's run (at least in the 2008 products and our machine). If they're run locally abstract base classes containing tests work as expected. However, those tests break when beeing run in TFS 2008 Team Builds.

HTH,

Bjoern

Monday, March 08, 2010 9:46 AM by Igor Brejc

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

It's not just NUnit vs MsTest. I've been using MbUnit (a.k.a. Gallio) for several years now and I never looked back. Most of the features (both NUnit's and MsTest's) you mentioned were present in MbUnit for some time now. And much, much more.

Monday, March 08, 2010 11:56 AM by Joe Wilson

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

I prefer the more natural and fluent assert syntax in NUnit, like:

Assert.That(x, Is.EqualTo(1));

instead of:

Assert.AreEqual(1, x);

NUnit also has a lot wider assert API, which I think makes the tests much more readable when you come back to them 6 months later.

Monday, March 08, 2010 1:28 PM by Bill Sorensen

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

In response to yaronn01:

"ReSharper 5 introduces a completely new approach to running your NUnit tests. Our engine is now based on native NUnit code. What it means to you is 100% compatibility with the latest released version of NUnit and full support of its recent unit testing features."

blogs.jetbrains.com/.../resharper-50-overview

Tuesday, March 09, 2010 3:52 AM by Markus Tamm » Blog Archive » Links 09.03.2010

# Markus Tamm » Blog Archive » Links 09.03.2010

Pingback from  Markus Tamm  » Blog Archive   » Links 09.03.2010

Tuesday, March 09, 2010 1:38 PM by ALSAGILE

# Stop the war between NUnit and MSTest : Make them friends

Stop the war between NUnit and MSTest : Make them friends

Tuesday, March 09, 2010 1:55 PM by Stephane

# re: NUnit vs. MsTest: NUnit wins for Unit Testing.

Why not using both?

I like the Assert API from NUnit, but I like the test report and easy automated build setup from TFS...

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Assert = NUnit.Framework.Assert;

see my blog for full article : alsagile.com/.../stop-the-war-between-nunit-and-mstest-make-them.aspx

# To work in .net using any of Asp.net,Vb.net,C# on Windows based … | C# WebDev Insider

Pingback from  To work in .net using any of Asp.net,Vb.net,C# on Windows based … | C# WebDev Insider