RowTestExtension 1.1.0 released

Yesterday I released the new version of the RowTestExtension, an addin for NUnit. I have made following changes:

  • Added ExpectedException property to the [Row] attribute. It can be used to specify which type of exception to expect when the given data is passed to the test.
  • The [Row] attribute accepts now null values.
  • Removed dependency from assembly NUnitExtension.RowTest.AddIn to NUnitExtension.RowTest.

You can download it from here.

Technorati Tags , ,

Kick It on DotNetKicks.com
Posted in .NET Development, TDD | Tagged , , | 4 Comments

Verifying exceptions using IExpectException

The unit tests for NUnit contain an interesting pattern for verifying exception details. The abstract class MessageChecker in assembly nunit.framework.tests implements IExpectException, an interface introduced with NUnit 2.4. Test cases in derived test fixtures set the protected field expectedMessage to the expected exception message which can span several lines or include data from the test setup.

Here is another example:

public class FileNotFoundExceptionChecker : IExpectException
{
	private string _expectedFileName;

	public FileNotFoundExceptionChecker()
	{
	}

	public void HandleException(Exception ex)
	{
		if (_expectedFileName == null)
			return;

		Assert.IsInstanceOfType (typeof (FileNotFoundException), ex);
		FileNotFoundException fileNotFoundException = (FileNotFoundException) ex;

		StringAssert.Contains(_expectedFileName, fileNotFoundException.Message);
		Assert.AreEqual(_expectedFileName, fileNotFoundException.FileName);
	}

	protected void ExpectMissingFile(string fileName)
	{
		_expectedFileName = fileName;
	}
}

[TestFixture]
public class FileTest : FileNotFoundExceptionChecker
{
	[Test]
	[ExpectedException(typeof(FileNotFoundException))]
	public void ReadAllBytes()
	{
		string fileName = @"C:\notexistingfile.txt";
		ExpectMissingFile(fileName);

		File.ReadAllBytes(fileName);
	}
}

Technorati Tags ,

Kick It on DotNetKicks.com
Posted in .NET Development, TDD | Tagged , | Leave a comment

RowTests with NUnit 2.4

I had some time last week and therefore I played around with the new extensibility features of NUnit 2.4. I wanted to know, how difficult it is to implement the RowTest feature of MbUnit as NUnit Addin. Two hours later the RowTest Extension for NUnit was ready. I released the extension under the MIT license.

The following code snippet shows you how to use the extension:

[TestFixture]
public class RowTestSample
{
	 [RowTest]
	 [Row( 1000, 10, 100.0000)]
	 [Row(-1000, 10, -100.0000)]
	 [Row( 1000, 7, 142.85715)]
	 [Row( 1000, 0.00001, 100000000)]
	 [Row(4195835, 3145729, 1.3338196)]
	 public void DivisionTest(double num, double den, double res)
	 {
	 	Assert.AreEqual(res, num / den, 0.00001);
	 }
}

The current release does not support all features of MbUnit RowTests, e.g. Exceptions cannot be tested.

Technorati Tags , , ,

Kick It on DotNetKicks.com
Posted in .NET Development, TDD | Tagged , , , | 33 Comments

Decorate Your Tests

In my last post I showed you how to write a minimal NUnit addin. It didn’t do anything useful, so let’s see what we can do with test decorators.

What Is a Test Decorator?

The Decorator Pattern describes a design for attaching additional responsibilities to an object dynamically. It is also known as Wrapper. Test Decorators wrap a single test case or a test fixture and therefore allow you to run some code before and after it.

Read More »

Technorati Tags , ,

Kick It on DotNetKicks.com
Posted in .NET Development, TDD | Tagged , , | Comments closed

How To Build an NUnit Addin

Since version 2.2.x of NUnit it was possible to build your own core extensions, but this feature was experimental. With the latest release Addins are officially supported. Core extensions can customize NUnit’s internal behavior such as the creation of tests and their execution.

Read More »

Technorati Tags , ,

Kick It on DotNetKicks.com
Posted in .NET Development, TDD | Tagged , , | 3 Comments

New Version of NUnit

Charlie Poole released NUnit 2.4.1 yesterday. It just fixes some issues and has some minor improvements.
I plan to examine the new extensibility features of NUnit 2.4. So expect some posts about it during the next weeks.

Technorati Tags ,

Kick It on DotNetKicks.com
Posted in .NET Development, TDD | Tagged , | Leave a comment

IronRuby Follows IronPython

Great news for dynamic language enthusiasts: Microsoft will implement Ruby on top of .NET. It will be called IronRuby and it will use the new Dynamic Language Runtime (DLR), a great platform for authoring and hosting dynamic languages. You can see a demo here showing interoperation between Ruby, Python, JavaScript, and Visual Basic.
The demo uses Silverlight, a browser plug-in for rich interactive web applications, as DLR host. Silverlight will run on all major browsers on both Mac OS X and Windows. Unfortunately this excludes all Linux browsers, but it seems that the Mono people are interested in implementing Silverlight for Linux.
The best thing, however, is that Microsoft makes the source code of the DLR, IronPython, and IronRuby available as open source under the Microsoft Permissive License (a BSD-style license).

Technorati Tags , , , , , ,

Kick It on DotNetKicks.com
Posted in .NET Development | Tagged , , , , , , | Leave a comment