exceptionz

Thoughts on Technology, Methodology and Programming.

NUnit vs. MSTest Behavior

Posted by Marcus Wyatt on 29 May 2006

I’ve found the following odd behavioural difference in Assert.AreEqual between NUnit and Microsoft.VisualStudio.TestTools.UnitTesting.

In NUnit you can specify the following test that will pass:

[TestMethod]
public void IntegerLongComparison()
{
Assert.AreEqual(1, 1L);
Assert.AreEqual(1L, 1);
}

But when you try to do the same with Microsoft’s Unit testing framework it fails.

So this got me thinking. When comparing value types, do you fail the assertion when the types differ?

One part of me says, No! When you think about it, an integer value of 3 is the same as a double value of 3.

3 are 3, isn’t it…?

Well, yes and no. I’m kind of torn between the two arguments. Not sure which way to go on this problem…

What do you feel is the right behavior?

tags: , ,

Currently listening to: ersion) – Winamp *** 1. 2 Brothers on the 4th Floor – Heaven is Here (Radio Version)

Advertisements

4 Responses to “NUnit vs. MSTest Behavior”

  1. The purpose of the unittest code is not to verify type safety. In my opinion, the nUnit behavior is better: the assertion should be loose.

  2. Can’t agree with you more. The following assert should pass in my opinion:

    double dValue = 3.0;
    int iValue = 3;
    Assert.AreEqual(dValue, iValue);

    But in the MSTest suite it does not…

  3. samegutt said

    This is no longer an issue in MSTest 9 (VS 2008).

    double amount = 100d;
    int roundedAmount = 100;
    Assert.AreEqual(roundedAmount, amount);

    actually asserts true, with the possibility to add a third parameter “delta” to AreEqual.

  4. Great, so it’s fixed now. Thanks for letting me know….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: