Search code examples
visual-studio-2015dnxxunit.net-corexunit2

xUnit.net v2 not discovering .NET Core Tests in Visual Studio 2015


I am really frustrated with this issue. I have already tried changing the version numbers but no tests are showing in the test explorer.

In the test output window I can see this output

Starting Microsoft.Framework.TestHost [C:\Users\sul\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.exe --appbase "path to test project" Microsoft.Framework.ApplicationHost --port 63938 Microsoft.Framework.TestHost --port 63954 list ]
Unable to start Microsoft.Framework.TestHost
========== Discover test finished: 0 found (0:00:36.5471185) ==========

This is so fragile, sometimes tests are shown then they disappear for good. Restarting VS didn't help, reinstalling the xunit/xunit runner didn't help either.

In another test project I got a different output but still not tests are showing

Starting Microsoft.Framework.TestHost [C:\Users\sul\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.exe --appbase "path to project" Microsoft.Framework.ApplicationHost --port 63938 Microsoft.Framework.TestHost --port 64421 list ]
Connected to Microsoft.Framework.TestHost
Discovering tests in 'path to project\project.json'
========== Discover test finished: 0 found (0:00:35.9341416) ==========

This is part of my project.json

"commands": {
    "test": "xunit.runner.dnx"
  },
  "dependencies": {
    "Microsoft.AspNet.Http": "1.0.0-*",    
    "Microsoft.AspNet.Http.Core": "1.0.0-*",
    "Microsoft.AspNet.TestHost": "1.0.0-*",    
    "Moq": "4.2.1502.911",    
    "xunit": "2.0.0",
    "xunit.runners": "2.0.0"

Solution

  • I manage to get this to work by making sure that all the packages in all the solution projects reference the same version.

    This happened to me because I was referencing the latest versions as you can see from project.json.

    One other thing I did is never reference individual packages which fits the purpose only. For example in my business project I am creating a middleware and I was referencing Microsoft.AspNet.Http because I don't need the full MVC package. This caused issues in the test project so I added Microsoft.AspNet.MVC to any project that needs any sort of Http interaction i.e. httpcontext.

    This may not be the ideal fix but it did work for me. I hope this helps someone else experiencing the same issue.