1

I'm new to C# and I am confused with the way NUnit and Visual Studio interact regarding exceptions.

From using it before, I remember that exceptions were thrown into the NUnit Gui "Errors and failures" tab, making the tests red - that is what I need now.

Now even Assert.Fail returns me to the VS window.

My setup is:

  • VS 2010 Express, NUnit 2.5.10
  • Main project is a 'Class Library' output
  • Launcher project is a starup project, 'Windows Application' output and has a reference to the main project
  • I run the tests from Visual Studio pressing 'debug' (this brings up the NUnit GUI window)
  • Launcher code:
namespace Launcher
{
    class Launcher
    {
        [STAThread]
        static void Main(string[] args)
        {
            NUnit.Gui.AppEntry.Main(new[] { "MainProject.dll" });
        }
    }
}

I know that I can open NUnit and then my dll and it will show exceptions inside NUnit window.

What I want is to press Debug and have NUnit to execute tests that I select, throw exceptions into NUnit window and make me able to set breakpoints - that worked before!

7
  • I'm guessing that your not running the nunit gui? Why not setup the gui to open up your test.dll that way?
    – Lareau
    Oct 26, 2011 at 14:03
  • The gui is being opened automatically with my dll
    – Andrey
    Oct 26, 2011 at 14:06
  • 1
    Why do you need this Windows application? Just use NUnit GUI as executable for debugging.
    – Alex F
    Oct 26, 2011 at 14:58
  • I am not sure this should be working in the first place. Somehow when starting your program in debug mode in VS, I would expect VS to react when an exception is thrown... Oct 26, 2011 at 15:02
  • Hi Alex, I need to press 'Debug' and have NUnit GUI pick my library up. If you would advise how this can be done in a better way, I'd be grateful.
    – Andrey
    Oct 26, 2011 at 15:06

1 Answer 1

4

Open up Nunit, Go to File --> Open project Navigate to the .dll of your unit test project, this should open up all your tests.

From here you can run all the test etc. You can setup nunit to run test everytime you rebuild your project (so ctrl-shift-b). No need to always press the debug button.

If you want to debug your test, (in vs2010), go to debug --> attach to process --> select nunit-agent.exe,
that should allow you to hit your breakpoints.

4
  • Thanks you for your answer, I have figured the first part by myself already, and it's not what I want. Regarding 'attach to process' - I don't have this menu option at all. What I want is to press Debug and have NUnit to execute tests that I select, throw exceptions into NUnit window and make me able to set breakpoints - that worked before!
    – Andrey
    Oct 27, 2011 at 8:19
  • I used to do that but it looks like in vs2010 but got into issues. Try this link - frater.wordpress.com/2010/05/04/…
    – Lareau
    Oct 27, 2011 at 11:38
  • Lareau, thanks for your answer, but I can debug tests just fine in my current config. The only thing that is not working is that exceptions are not thrown into NUnit GUI.
    – Andrey
    Oct 28, 2011 at 9:17
  • (debug --> attach to process) is not available in the Express Edition. Doing something along the lines of NUnit.Gui.AppEntry.Main(...) is needet there.
    – Johannes
    Oct 2, 2012 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.