简体   繁体   中英

How to make Visual Studio throw exceptions into the NUnit gui?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM