This post originated from an RSS feed registered with .NET Buzz
by Peter G Provost.
Original Post: NUnit Assert.AreEquals Parameter Ordering
Feed Title: Peter Provost's Geek Noise
Feed URL: /error.aspx?aspxerrorpath=/Rss.aspx
Feed Description: Technology news, development articles, Microsoft .NET, and other stuff...
I regularly take jabs at my boss Jim Newkirk (original author of NUnit 2.x), telling him, “I think you put the parameters to AreEqual in the wrong order. It should be actual, expected and not the other way ‘round.”
To which he consistently replies, “Well, you would be wrong.”
But all kidding aside, I still find myself writing code that assumes the AreEqual method has the opposite ordering.
It comes from the way I write if() statements. I write them like this:
if( myVariable == 4 )
{
// Do something
}
I have seen C/C++ programmers do this…
if( 4 == MyVariable )
{
// Do something
}
…as a way to protect themselved from forgetting the second = symbol (in fact I used to do it too). But as the C# compiler won’t let me make that mistake, I don’t do it anymore.
Which is why I want to write…
Assert.AreEqual( myVariable, 4 );
...instead of...
Assert.AreEqual( 4, myVariable );
But apparently, I'm wrong. But I still type it the other way more often than not.