How to debug with vs.net 2008 and nunit?

▼魔方 西西 提交于 2019-12-12 03:21:49

问题


I am running vs.net 2008 with nunit runner.

If I set a breakpoint in the unit test code, it just runs the unit test in the runner.

I'm guessing I have to integrate nunit with vs.net somehow?

My unit tests are just a class library project, I cannot run the tests in vs.net 2008, I can only do it via the runner currently.


回答1:


If you want to debug in your current setup (running nunit runner that has your assemblies loaded), do the following:

  1. Run nunit.exe
  2. Open (or create) your nunit project (File > New/Open Project
  3. Under Tools > Settings, click IDE Support > Visual Studio and check 'Enable Visual Studio Support'
  4. Once your nunit file is setup and you are ready to run, go to VS and click Tools > Attach To Process...
  5. Verify that 'Managed Code' is selected in the 'Attach to' area
  6. Find unit.exe, select it, and click Attach
  7. Place desired breakpoints in the library
  8. From the nunit GUI, click Run
  9. If youre debugging the correct assemblies, it should hit your breakpoint.

Ideally, I would change it to run nunit as an external program and supply your .nunit project file as the input. See here for more details.




回答2:


I am running vs.net 2008 with nunit runner.

If I set a breakpoint in the unit test code, it just runs the unit test in the runner.

(emphasis mine)

You just answered your own question. Why would you expect the Visual Studio breakpoint to magically push you into Visual Studio when you don't run the code via Visual Studio in the first place?

I would recommend refactoring your tests so that as many tests as possible can be run through Visual Studio (see http://www.nunit.org/index.php?p=vsSupport&r=2.2.10 for details on NUnit support for Visual Studio), and then only run the remaining tests on the console.




回答3:


To gain debugging unit tests with VS 2008, do the following:

1) Create project in NUnit runner and add your dll with unit tests into it.
2) Set up "Start external program" in your unit test project - NUnit exe file.
3) When you debug set up your unit tests project as "startup project" or whatever you have in VS2008.
4) Run



来源:https://stackoverflow.com/questions/9202369/how-to-debug-with-vs-net-2008-and-nunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!