3

how do I debug in visual studio with NSpec? I've resharper installed I need to step into my test code.

Amir
  • 9,091
  • 5
  • 34
  • 46
Mantisimo
  • 4,203
  • 5
  • 37
  • 55

4 Answers4

3

Another good option is to just type

  System.Diagnostics.Debugger.Launch()

in the test you want to debug. You'll get a Visual Studio prompt to debug the test.

I would also recommend taking a look at specwatchr.

Amir
  • 9,091
  • 5
  • 34
  • 46
  • 1
    Thanks, I have used this but it feels a bit clumsy. I'd prefer to use the resharper test runner if it were possible. I resided to using mspec which allows for this. I would consider switching in future if reharper was supported. I've managed to make it work with a shim but again this felt clumsy. I've also used specwatchr but I find it distracting, I prefer ncrunch's integrated solution for continuous testing. – Mantisimo Aug 15 '12 at 16:03
  • 1
    @Mantisimo NCrunch is definitely nice. What specwatchr gives you is the ability to "scale". For example, there may will come a point where you'll need to do out of proc tasks like deploying a website or resetting a database before your tests run, specwatchr is integrated into rake to allow you to do such tasks :-) – Amir Oct 16 '12 at 13:53
  • Having to modify source code to use the debugger should only be a last resort. I hope there are plans to make specwatchr more accessible. – Vimes Aug 08 '14 at 20:32
  • Thanks, @Amir. I did figure that out, eventually. I wrote it ;) – Vimes Aug 24 '14 at 18:37
  • 1
    @JohnB Oh! Ha!!! Did you see my comment on the git repo? I'll be adding it to NSpec.org soon. – Amir Aug 24 '14 at 19:29
  • I didn't see, but that's great news. :) – Vimes Aug 24 '14 at 22:49
2

At least in Visual Studio 2013, the NSpec Test Adapter (by {o} Software) seems to do the trick. Find it in the Extensions gallery. Then just right-click on the test in the Test Explorer and hit Debug.

enter image description here

Vimes
  • 10,577
  • 17
  • 66
  • 86
1

I use a simple trick that let's me debug NSpec with resharper out of the box. The idea is to have your own version of "nspec" class instead of DebuggerShim.cs (somewhere in your test project):

[TestFixture]
public abstract class nspec: global::NSpec.nspec
{
    [Test]
    public void debug()
    {
        var currentSpec = this.GetType();
        var finder = new SpecFinder(new[] {currentSpec});
        var builder = new ContextBuilder(finder, new Tags().Parse(currentSpec.Name), new DefaultConventions());
        var runner = new ContextRunner(builder, new ConsoleFormatter(), false);
        var results = runner.Run(builder.Contexts().Build());

        //assert that there aren't any failures
        results.Failures().Count().should_be(0);
    }
}

After that you will get Resharper's test icon next to your spec: nspec testing

For more details see this article: Debugging NSpec with VisualStudio/Resharper – simple trick

frizik
  • 1,766
  • 1
  • 13
  • 17
0

Resharper supports NUnit and MSTest runners only (AFAIR). Open the Resharper "Unit Test Explorer" window and see if it lists your NSpec tests there..

If not, you need to fallback to specifying an external program for debugging (The NSpec runner exe) - See this question on how to configure this in Visual Studio.

Community
  • 1
  • 1
Gishu
  • 134,492
  • 47
  • 225
  • 308