Home » TDD » Run NUnit from Visual Studio

Run NUnit from Visual Studio

For the purposes of this post, I’m going to assume that you already have the NUnit Test Runner installed.  The question you are looking to get answered is, “How do I run NUnit from Visual Studio” or even more importantly, “How do I DEBUG NUnit test from Visual Studio”.  The following step by step should help you.

Right click on the project in Solution Explorer that represents your test project. From the resulting menu, select “Properties.” In the resulting window, selec the “Debug” tab from the left-hand side of the window.


You will want to select “Start external program” and point it to the UNnit runner that got installed when you installed NUnit.

Now, whenever you run this project, with or without the debugger, NUnit will start up. Note: there is no reason to pass parameters telling it what DLL you want to run because it will load the last DLL it had up. But, if you wanted to do that, you could pass the location of the DLL as a parameter to the GUI runner. There are other parameters you can us. Check the documentation for the version of NUnit you are using for the specifics.

If you are running .NET 4.x, you’ll want to go to the location in your file system where NUnit.exe lives and find the NUnit.exe.config file. Find the startup element (<startup> …. </startup>) and place this line in between the open and close startup tags:

<supportedRuntime version="4.0" />

If you miss this step, you won’t be able to debug your 4.0 code. Alternatively, you can just set your project to use .NET 3.5.

So, let’s give it a try.

First, put some code in the test method you just created. For our purposes, we’ll just put in a console writeline so we have somplace to put a breakpoint.

public void MyFirstTestMethod()
    Console.WriteLine("Inside MyFirstTestMethod");

Next set a breakpoint on the Console.WriteLine method and then run your project with the debugger.

Once NUnit loads the DLL, click the “Run” button in NUnit. If everything is setup correctly, you should stop on the breakpoint you set.

You may have noticed that we put several Console.WriteLines() in our code but they aren’t displaying anywhere.  So, where did they go?  How can we see them?

By default the “Text Output” tab displays all of the Console.WriteLine() messages as well as all of the test results.  If all you care to see is the test results, you should select the “Errors and Failures” tab.  Personally, I prefer to work in the “Text Output” tab and I suggest that you do the same.

As an alternative to this, you can just pick up a copy of ReSharper, which has an NUnit Test Runner built into it.  All you need to do to debug a test is selection the test and choose debug from the context menu.  It will save you a ton of time.

Another option would be to pick up the MS Test Adapter from nunit.org.  But, I’ve never liked the way MS Test renders the tests results.  So, I don’t recommend it.  Obviously, your mileage may vary.

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it […]
  • Running Selenium In Parallel With Any .NET Unit Testing ToolRunning Selenium In Parallel With Any .NET Unit Testing Tool Running Selenium in parallel from .NET seems to be a problem because, as of the time of this writing, I’ve yet to find a viable way of running selenium test on multiple browsers using […]
  • What is SpecFlow…What is SpecFlow… …And why do I want it? That’s what I kept asking myself every time I saw this product.Well, the last time I looked, something caught my eye enough that I decided to download it and […]
  • CT Code Camp DemosCT Code Camp Demos For those that attended my presentations at the CT DotNet User’s Group Code Camp this last weekend, here are the links to the demos that I promised.TDD with NUnitTesting Websites […]
  • The Programmers’ RevoltThe Programmers’ Revolt Every once in a while, something happens in life that makes you say, “enough!”That happened a couple of weeks ago to me and a couple other programmers working on the same project […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer. His commitment to quality through test driven development, vast knowledge of C#, HTML, CSS and JavaScript as well as his ability to mentor younger programmers and his passion for Agile/Scrum as defined by the Agile Manifesto and the Scrum Alliance will certainly be an asset to your organization.

2 Pingbacks/Trackbacks

  • Pingback: Dew Drop – April 30, 2015 (#2004) | Morning Dew()

  • Pingback: Automate the Planet()

  • http://automatetheplanet.com/ Anton Angelov

    Hi Dave,

    Great article!

    Can you please share why you don’t like the MSTest default results?

    As you mentioned at the end of the article, the whole NUnit integration is built-in in the new versions of Visual Studio (> 2012). Thus, I’m not sure why it is necessary to put all of this effort if you have a pretty handy feature built-in.

    Also, I included your fantastic article in my weekly roundup, you can check it here: http://automatetheplanet.com/compelling-sunday-24-posts-on-programming-and-quality-assurance/


    • http://blog.dmbcllc.com/ Dave Bush

      I prefer the nested rendering that NUnit and ReSharper provide. MS Test renders everything flat.

      You are correct that the latest versions of Visual Studio have MS Test included, but Visual Studio Express does not, nor do all of the versions of Visual Studio prior to 2012. Unfortunately, there are still some companies that haven’t felt the need to upgrade who could benefit from Unit Test.

      So, running NUnit from Visual Studio is A way, but not the only way as I acknowledge in the article.

      Thanks for the links.

      • http://automatetheplanet.com/ Anton Angelov

        Yeah, I guess you are right.

        Maybe I have had the luck to work in a company where I’m able to use always the latest version of everything.

        Also, you are right about the flat structure of MSTest results. In my team, we have set up the test results to be published in Jenkins. I enjoy how they are rendering now. You can check it.

        • http://blog.dmbcllc.com/ Dave Bush

          Seeing them render in Jenkins is cool, but I would hope developers are running unit test prior to checking the code in and potentially breaking the build.