简体   繁体   中英

How to debug in Visual Studio with NSpec

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

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 .

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.

在此输入图像描述

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测试

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.

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