Monday, October 19, 2009

Using the Visual Studio .NET Debugger with NUnit-Gui













Using the Visual Studio .NET Debugger with NUnit-Gui

As you write more and more programmer tests, you might spend less time debugging your application. Small and isolated programmer tests usually do a very good job of narrowing down bugs to a few lines of code. However, sometimes you might need to use a debugger to locate a particularly slippery bug. Let’s say you have a failing programmer test, but you cannot identify the problem by simply looking at the code. Fortunately, using the Visual Studio .NET Debugger with NUnit-Gui is very straightforward.


First, you need to set up NUnit-Gui as your test runner with Visual Studio .NET (this process was described earlier). Second, you need to set a break point in the failing programmer test code and start the application in the Debug mode. Let’s demonstrate this with our NumberFixture class. We will make a change to the AddTwoNumbers method to make it fail:


[Test]
public void AddTwoNumbers()
{
int sum = a + b;
Assert.AreEqual(4, sum);
}

We changed the expected value from 3 to 4, and the test now fails. Now we can set up a break point in the AddTwoNumbers method and start the Debug session. NUnit-Gui will appear and we will hit the Run button. When the execution reaches the AddTwoNumbers test, the Debugger will stop at the break point. Figure A-7 demonstrates this state:






Figure A-7: Using Visual Studio .NET Debugger with the NUnit-Gui test runner

Now we can debug the application as usual. The problem with the code is fairly obvious.











No comments:

Post a Comment