Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Nunit Tests inside VS2010 Express

I have written a bunch of unit tests inside VS2010 Express and tests being tests they sometimes fail. Since the express editions of VS don't allow plugins to run I can't simply spin up TestDriven.Net or an equivalent and debug the tests. To try and work around this I've converted my test assembly into a console app and made the main method look like this:

class CrappyHackToDebugUnitTestInVSExpress
{
  public static void Main()
  {
     AppDomain.CurrentDomain.ExecuteAssemblyByName(
          @"C:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit-console.exe",
          new [] { Assembly.GetExecutingAssembly().Location, "/framework:4.0" });
  }
}

In theory I should be able to run this up, set break points in my test. If it worked it would be an acceptable work around, but I keep getting the following:

FileLoadException
Could not load file or assembly 'C:\\Program Files\\NUnit 2.5.5\\bin\\net-2.0\\nunit-console.exe' 
or one of its dependencies. The given assembly name or codebase was invalid. 
(Exception from HRESULT: 0x80131047)

Now the file exists and when run manually nunit-console runs fine. What might be my problem?

like image 260
ilivewithian Avatar asked Jun 08 '10 18:06

ilivewithian


People also ask

How do I debug a NUnit 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".

Can I use NUnit with .NET core?

Sdk version 17.0. 0 to your NUnit test projects will also enable the dotnet test command for . NET Core projects.

How do you debug unit test cases?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.


1 Answers

Basically you need to convert your assembly to Windows Forms app, add reference to the nunit-gui-runner.dll assembly and change your Main method to look like this:

    [STAThread]
    static void Main()
    {
        NUnit.Gui.AppEntry.Main(new string[] { Assembly.GetExecutingAssembly().Location });
    }

here is another example:

...
using NUnit.Gui;

namespace __libs
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            NUnit.Gui.AppEntry.Main(new string[] { @"C:\test\bin\Debug\test.exe" });
        }
    }
}

This will allow you to step into certain tests but is not very good for a red green cycle, so you will want to use this only when debugging and not in other circumstances.

like image 193
Dmitry Osinovskiy Avatar answered Oct 12 '22 22:10

Dmitry Osinovskiy