dotnet-test-nunit
dotnet-test-nunit copied to clipboard
Debugging with VSCode
First off, thank you for this project.
It took me a while to figure out how debug NUnit tests in VSCode. What I ended up doing was creating a command line project as so:
dotnet new
then I replaced Program.cs with the following
using System;
using System.Reflection;
using NUnit.Common;
using NUnitLite;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var writer = new ExtendedTextWrapper(Console.Out);
new AutoRun(typeof(Program).GetTypeInfo().Assembly).Execute(args, writer, Console.In);
}
}
}
(as you mentioned in this SO answer)
I see that someone tried to do it "natively": http://disq.us/p/1a0t192 . But it looks like this project is missing some hooks to VSCode.
Since F5 runs Main which runs the tests, this allows debugging in VSCode.
To compare with xunit (which lives here), you can run the following command to generate the necessary files:
dotnet new -t xunittest
then in the UI simply F5 and you can set breakpoints in the test.
Even more conveniently, the editor includes over tests "run test" and "debug test" options.
Questions
- Is there currently a better way to do this that I am missing?
- Is there plans for mirroring what xunit does, both in terms of generating a test project and debugging the tests naturally via the editor?
- Would you like some help implementing if things are missing? :)
We will need to look at the build/test settings in VSCode, but you should be able to debug NUnit tests by setting up the test command the same way that xUnit does it. I need to look at it, but I would guess that the C# extension for VSCode detects xUnit tests and sets up the test target automatically. It will likely need to be modified to work with NUnit although you can likely set it up manually.
Using NUnitLite to debug your tests works, but we should figure out how to do it using dotnet-test-nunit
.
Generating the test project is part of the dotnet CLI project. An NUnit template has been added and will be available with the next release of the CLI tooling.
We are always looking for help. Even just tracking down the code in the VSCode C# extension (if that is where it is) and figuring out the tasks for VSCode would help. If there are other ways you want to chip in, then comment on issues you would like to work on and I will help you get started.
@ivanmartinvalle How are you debugging tests in VSCode? The only way I have managed is through the code lens above the XUnit test.
This file in the C# extension adds the code lens test commands for XUnit only, see lines 81+ https://github.com/OmniSharp/omnisharp-vscode/blob/master/src/features/dotnetTest.ts
I haven't found yet where/how the Features are identified. That may be in OmniSharp itself.
Looks like the XunitTestMethod
feature is discovered in https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.DotNetTest/Helpers/TestFeaturesDiscover.cs
@rprouse My project is just a command line project that uses NUnitLite to run ALL tests in the project. When I set a breakpoint inside the test and I hit F5, it's the same thing as debugging a normal application (which itself should be pretty straightforward).
I'm using Mac OS X if it matters, but I don't think it does.