Search code examples
unit-testingvisual-studio-2015dnxxunit2

Unable to load application or execute command 'Microsoft.Dnx.TestHost'. Available commands: test


Trying to test an ASPNET 5 application in VS2015.

{
  "version": "1.0.0-*",
  "description": "HoldingTank Class Library",
  "dependencies": {
    "EntityFramework.InMemory": "7.0.0-rc1-final",
    "FluentAssertions": "4.1.1",
    "GenFu": "1.0.4",
    "MyMVCProject": "1.0.0-*",
    "xunit": "2.1.0",
    "xunit.runner.visualstudio": "2.1.0"
  },
  "commands": {
    "test": "xunit.runner.dnx"
  },
  "frameworks": {
    "dnx451": { }
  }
}

However, no tests show up in the Test Explorer window and when I hit F5 I get:

------ Discover test started ------
------ Test started: Project: HoldingTank ------
Starting  Microsoft.Dnx.TestHost [C:\Users\erik\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin\dnx.exe --appbase "C:\code\PortalSolution\src\HoldingTank" Microsoft.Dnx.ApplicationHost --port 52620 Microsoft.Dnx.TestHost --port 56351 --parentProcessId 8368]

Error: Unable to load application or execute command 'Microsoft.Dnx.TestHost'. Available commands: test.
Unable to start Microsoft.Dnx.TestHost
   ========== Discover test finished: 0 found (0:00:01.8238001) ==========

I just have one test, decorated with [Fact] but it doesn't look like it is getting that far.

Looking at similar questions that have "unable to load" errors (but couldn't find any specific to TestHost), I've tried making sure that both the test project and the application target the same frameworks, but couldn't find any discrepancies. And I don't see anything in the Event Log.

Any suggestions? - not even sure where to go to start to troubleshoot this.


Solution

  • You have to add the "xunit.runner.dnx" as dependency instead of the "xunit.runner.visualstudio". Then it will work in VisualStudio.

    Since ASP.Net 5 is in beta, so is xunit.runner.dnx. Use the current pre-release which matches ASP.Net RC1 ... I currently use 2.1.0-rc1-build204 with ASP.Net 5 RC1