Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top