Showing posts with label Unit Tests. Show all posts
Showing posts with label Unit Tests. Show all posts

Wednesday, February 3, 2010

Test-free features?

@YaronNaveh

At some mature stage of a system development we replace all of these messages:


throw new Exception("should never see this")


with something more customer oriented:


throw new Exception("An error has occur while loading the document. Please verify it is in the correct format. ")


Or even better - doing globalization:


throw new Exception(Resources.UnknownLoginError)


These changes are not expected to cause any non-UI regressions, right?

Consider the case where we originally had this


String.Format("Cannot download url");


And now the documentation guys kindly asked to change to this:


String.Format("Cannot download url {0}", url);


or this:


String.Format("Cannot download url {0} using credentials {1}:{2}", url, user, pass);


A mismatch between the number of tokens in the string to the actual provided parameters may result in this error:


Index (zero based) must be greater than or equal to zero and less than the size of the argument list.


Conclusion: Proofing/Localizing always require running all your tests and doing a regression cycle.

@YaronNaveh

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

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!

Thursday, June 25, 2009

Unit Tests Presentation

@YaronNaveh

Yesterday I have conducted a session on Unit Testing.
My presentation answers the most common questions on the matter:

  • What to test?
  • When to test?
  • How to write a good unit test?

    And most important the presentation is full of examples.

    Download it from here



    Feel free to use it or present it whether you are a developer, a tester or a TDD evangelist.

    @YaronNaveh

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