How to debug with vs.net 2008 and nunit?

2019-09-08 05:35发布

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.

3条回答
放荡不羁爱自由
2楼-- · 2019-09-08 06:19

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.

查看更多
乱世女痞
3楼-- · 2019-09-08 06:30

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.

查看更多
看我几分像从前
4楼-- · 2019-09-08 06:32

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

查看更多
登录 后发表回答