Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Nunit test in Visual Studio 2010

Tags:

I have a problem debugging an NUnit test from VisualStudio. I created an empty project (Console Application), then I added references to the NUnit library and wrote a simple test.

namespace ReimplementingLinq.Tests
{
    [TestFixture]
    public class WhereTest
    {
        [Test]
        public void SimpleFiltering()
        {
            int[] source = { 1, 2, 3, 4, 2, 8, 1 };
            var result = source.Where(val => val < 4);
            int[] expected = {1,2,3,4};
            CollectionAssert.AreEqual(expected, result);
        }
    }
}

Next I followed the advice given in this link How do I run NUnit in debug mode from Visual Studio? but none of the solutions in that topic work for me. None of my breakpoints are hit while performing the test. I tried testing the solution by attaching to the process and also by running the project with an external program with arguments.

What can I do to debug my unit test?

like image 771
commando Avatar asked Jul 24 '11 13:07

commando


People also ask

How do I debug NUnit tests in Visual Studio?

If you would like to debug your tests, use the Visual Studio Debug | Processes... menu item to attach to NUnit after starting it and set breakpoints in your test code as desired before running the tests.

Can I debug unit test?

Options. If the selection point in the current code window is within a NUnit test, then under the right mouse click context menu, there will be a new option "Jonno - Debug Current test". Set a break point within the text of the test, use the menu option, and you should be able to immediately debug your test.


1 Answers

Running or debugging NUnit tests directly with Visual Studio

Look ma' no extensions!

Simply configure your test project so that when you hit F5 (Start debugging) or Ctrl-F5 (Start without debugging) it will automatically start NUnit GUI and execute all tests within it. If any breakpoints get hit, you will also be able to simply debug your test code.

A step-by-step guide with images shows you exactly how to do it.

Laziness is the mother of all invention :-)

like image 61
Robert Koritnik Avatar answered Oct 10 '22 18:10

Robert Koritnik