Showing posts with label NUnit. Show all posts
Showing posts with label NUnit. Show all posts

Friday, January 22, 2010

ReSharper and NUnit - A word of warning

@YaronNaveh

A lot of people prefer the shiny ReSharper test runner over the NUnit GUI. The main reason is of course that it is embedded in the VS IDE.

In some cases this means trouble.

Let's look in this test:


[Test]
[ExpectedException(ExpectedMessage = "my error", MatchType=MessageMatch.Contains)]
public void myUnitTest()
{
  throw new Exception("my error");
}


Does this test pass or fail? It depends who you ask.

ReSharper says:



NUnit says:



The reason is that the ReSharper runner does not know the "ExpectedException" attribute of NUnit. Who knows, maybe it's just a version thing and some x.y.z version of ReSharper knows how to work with the u.v.w version of NUnit. The lesson is that when you have two clocks you never know what the real time is...

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Saturday, December 26, 2009

When your unit test is not implemented...

@YaronNaveh

When your unit test is not implemented yet you want to make sure everybody knows about it. One bad way is to throw an exception in the test first line:


[Test]
public void MyNewTest()
{
   throw new NotImplementedException();
}


The reason is that when you see in the report this failure you can never tell if the error comes from the unit test or the application under test...

The good solution is to use a build in feature of your unit test framework. For example, the Ignore attribute in NUnit. If for some reason you have to throw an exception (so the test will be red) at least throw some better error class like "new UnitTestNotImplementedException()".

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

Unit Test Legitimic Failures

@YaronNaveh

Our unit tests are expected to pass every time. When they fail we are expected to fix the regression. But in some cases it is ok for a test to temporarily not pass. For example, if the test is a small regression in a minor feature and we are currently employed with other critical missions. But while the test is failing we should at least make sure it will not cause any noise like spamming out the team.

When we use NUnit, the solution is the Ignore attribute:


[Test]
[Ignore]
public void SomeTest()
{
//...
}


The test is not red any more:

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!