简体   繁体   中英

Debugging unit tests with resharper

I've just started using resharper and I found a very annoying thing about it. When debugging a unit test, I try to step-into (F11) a method, but visual studio complains that source code is not available. The problem is that resharper is wrapping method calls with its own classes. Of course I can put a braeakpoint further in my source, but this is very annoying. Do you know if there´sa solution for this? By the way, I'm using NUnit to write my tests

Thanks

Federico

After some playing around I managed to recreate this on my setup (Xunit.net in resharper, visual studio 2008)... The steps I took to recreate this are:

  1. Set the dll that contains the tests as the startup project (I know you don't need to do this, was just trying to get it to fail)
  2. Put a breakpoint in the unit test
  3. Push F11 (the shortcut key for 'step into' in my configuration)
  4. This complains 'Cannot start test project 'RowanBeach.Crm.Domain.Test' because the project does not contain any tests.'
  5. Run the 'Debug Unit Tests' command from the Resharper menu (I have this bound to a key combination on my machine)
  6. This displays the 'No source code available...' message

Of course that's not how you should start unit tests from resharper! :) If that's what you were doing (or something similar), try this instead:

  1. Don't bother setting the dll as the startup project - it doesn't need to be
  2. build or rebuild the dll that contains the tests
  3. set the breakpoint
  4. Put the cursor somewhere in the source code for the unit test you want to debug to set it as the 'current context' unit test
  5. Run the 'Debug Unit Tests' command from the Resharper menu (You might want to bind this to a key combination if you haven't already)

Hopefully, that should work

What type of tests are you running - NUnit? MS Test? Something else?

I've never found it difficult to debug tests using R# - just put a breakpoint in your test and go. What method are you trying to step into? I've generally not tried to step into the NUnit methods themselves (assertions etc) but stepping into your own code should be okay.

If you can come up with a quick example, I'd be happy to try it myself.

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