Sdk: Enable debugging of tests with dotnet test

Created on 3 Feb 2016  路  23Comments  路  Source: dotnet/sdk

Find a way to allow for debugging when using dotnet test

Area-DotNet Test enhancement

Most helpful comment

I came across this issue because I was looking for a way to debug tests launched from the command line. I came across this line that indicates that if you set $env:VSTEST_RUNNER_DEBUG=1 then you can use dotnet test and it will wait for the debugger to attach before continuing execution. I verified that this does work. Hopefully this is helpful for others.

All 23 comments

A --debug flag that allows you to attach to the process might be the first step

Currently the only way I was able to get debugging in visual studio was to add System.Diagnostics.Debugger.Launch(); to the source. Is that seriously the only way to debug anything right now?

@programatt - you can also do Console.WriteLine() :imp:

+1

We have added a dotnet test debug experience in VS.

@livarcocc Is this documented somewhere?

@livarcocc is this documented ? or is this issue still opened ?

I am not sure about the documentation. But it is just like any other tests in VS.

@livarcocc I don't really understand what you mean. If you've added a "dotnet test debug experience", how is a user supposed to invoke it? I'd imagine there's some command line flag or options you have to pass to dotnet test, but I can't see this documented anywhere.

What I mean is that you can do that in VS, but not in the command line.

Documentation would be really helpful here! I haven't been able to figure this one out.

@livarcocc Why is this issue closed? As far as I can tell, the issue hasn't actually been resolved as described.

What I mean is that you can discover tests for core in VS and debug them through VS.

Ah, okay.

I guess I assumed this issue was more about being able to add a flag such as --debug to dotnet test in order to allow the debugging of all discovered test cases via the CLI for use in applications like VSCode.

What I mean is that you can discover tests for core in VS and debug them through VS.

And what about tests that don't fail in Visual Studio but fail when running dotnet test? How do we debug those?

nunit3-console https://github.com/nunit/docs/wiki/Console-Command-Line has --debug option.

I think that's really easy and useful if you want to debug without visual studio or for some other (buggy) reason!

Reopen this!!!

I agree that the issue has not been resolved and should be reopened.

Please, file an issue under microsoft/vstest for this.

I came across this issue because I was looking for a way to debug tests launched from the command line. I came across this line that indicates that if you set $env:VSTEST_RUNNER_DEBUG=1 then you can use dotnet test and it will wait for the debugger to attach before continuing execution. I verified that this does work. Hopefully this is helpful for others.

Setting $env:VSTEST_HOST_DEBUG=1 allows you to debug the actual tests being run

Setting $env:VSTEST_HOST_DEBUG=1 allows you to debug the actual tests being run

on linux/mac: export VSTEST_HOST_DEBUG=1

You can add an entry point to your Unit Test project, in a file called Program.fs (for F#). I was able to debug my NUnit tests like this:

namespace BackendTest

open RebelSoftware.UnitTests.ControllerTests

module Program =
[]
let main args =
//this entry point is the only way to debug unit tests
let employeeControllerTest = EmployeeControllerTest()
employeeControllerTest.Setup()
employeeControllerTest.ReturnsResponseFromMQWhenRequestBodyIsValid()
0

I came across this issue because I was looking for a way to debug tests launched from the command line. I came across this line that indicates that if you set $env:VSTEST_RUNNER_DEBUG=1 then you can use dotnet test and it will wait for the debugger to attach before continuing execution. I verified that this does work. Hopefully this is helpful for others.

I almost got this to work. When I try to attach vs 2019 complains about vstest.console.pdb not being loaded. Then all my breakpoints become the "red outline circles" instead of being filled in letting me know the breakpoint will not be hit.

The UX for all this isn't very good and I wish there was better documentation\solutions for attaching a debugger to 'dotnet test' execution.

image

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natemcmaster picture natemcmaster  路  3Comments

dasMulli picture dasMulli  路  3Comments

billwert picture billwert  路  3Comments

gkhanna79 picture gkhanna79  路  3Comments

joffreykern picture joffreykern  路  3Comments