1

I have a dotnetcore solution containing a service layer project along with a test project for this service layer.

According to this SO post from 2016 vscode should be able to automatically detect my xunit tests and allow me to debug and run them individually. However, when i open file containing an xunit [fact], i am not seeing any options that allow me to debug the test: enter image description here

I think this may be related to the new .csproj structure of dotnet core, instead of the old json format.

I am able to debug the tests in visual studio 2017 on windows, any way to also enable this on vscode for osx?

Jurgen Welschen
  • 871
  • 1
  • 13
  • 21

2 Answers2

0

You should add the following references in order for VS to detect your tests. This is how your project.json should look like:

{
  "version": "1.0.0-*",

  "dependencies": {
    "xunit": "2.2.0",
    "dotnet-test-xunit": "2.2.0-*",
    "xunit.runner.visualstudio": "2.2.0",
    "Microsoft.AspNetCore.TestHost": "1.1.2",
    "Microsoft.DotNet.InternalAbstractions": "1.0.0",
    "Microsoft.NET.Test.Sdk": "15.0.0",
  },
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.1"
        }
      },
      "imports": [
        "dotnet5.4",
        "portable-net451+win8"
      ]
    }
  },
  "testRunner": "xunit"
}

The important part is that you have to have the testrunner set as xunit and also add the Microsoft.DotNet.InternalAbstractions as well.

I found this after struggling for an hour or so...

svick
  • 236,525
  • 50
  • 385
  • 514
Yaser
  • 5,609
  • 1
  • 15
  • 27
0

No action on this thread for two months, so here's my contribution.

Are you running dotnet test from the test directory? I had the same problem (in VSCode on OSX), naively expecting tests to run from the solution directory. They don't.

Sisyphus
  • 11
  • 2