问题
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"
回答1:
I've just had some issues with this when using TFS. Set it up and got it working on one machine, went onto another, Got latest code after checking in my changes, everything was showing correctly, but the test runner wasn't finding any tests at all. In the end a simple clean and rebuild on the Test project fixed it and it now finds tests.
This is my project.json
"dependencies": {
"Xunit": "2.1.0-beta2-*",
"Xunit.runner.dnx": "2.1.0-beta2-*"
},
"commands": {
"test": "xunit.runner.dnx"
},
Note the capital X in the Xunit listed in dependencies. The official documentation lists is as a lower case x, but this does not work. I've emailed the repo owner to make him aware of this.
EDIT: I've spoken to the author of XUnit who assures me the lower case x does work for him and others and that it's potentially a corrupted package cache.
回答2:
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.
回答3:
I had some issues but got it working !
"dependencies": {
"Test.ANNe.Compiler": "1.0.0-*",
"xunit.runner.dnx": "2.1.0-beta2-build79"
},
"commands": {
"Test.Console": "Test.Console",
"test": "xunit.runner.dnx"
},
3 issues i had . 1. You can only have 1 runner ! 2. Test in command 3. Ensure the compile environment matched the environment setup in dnvm
I note your using dnx-clr-win-x86.1.0.0 which is dnx but not the dnx runner.
回答4:
The following dependencies (to be provided in project.json) worked for me (original source):
"dependencies": {
"System.Collections": "4.0.10-beta-23019",
"System.Linq": "4.0.0-beta-23019",
"System.Threading": "4.0.10-beta-23019",
"System.Runtime": "4.0.10-beta-23019",
"Microsoft.CSharp": "4.0.0-beta-23019",
"xunit": "2.1.0-*",
"xunit.runner.dnx": "2.1.0-*",
"xunit.runner.visualstudio": "2.0.1",
"Microsoft.Framework.TestHost": "1.0.0-*",
"Microsoft.Framework.ApplicationHost": "1.0.0-*"
}
回答5:
Encountered similar issues, and changing from xunit 2.0.0-rc1 to 2.0.0-beta8 fixed the issue.
Details:
- Project A (older version of Microsoft.AspNet.Authentication.Test) worked
- Project B (my custom project) did not work
Setting Project B to use:
"xunit.runner.aspnet": "2.0.0-aspnet-beta8*"
Instead of:
"xunit.runner.aspnet": "2.0.0-aspnet-*"
Fixed the issue. Project B was picking up:
xunit.runner.aspnet (2.0.0-aspnet-rc1-15669)
Project A used the following project.json:
{
"compilationOptions": {
"warningsAsErrors": "true"
},
"dependencies": {
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
"Microsoft.AspNet.Authentication.Google": "1.0.0-*",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-*",
"Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-*",
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
"Microsoft.AspNet.DataProtection": "1.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Moq": "4.2.1312.1622",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Shouldly": "1.1.1.1"
}
}
}
}
Project B used:
{
"dependencies": {
"Microsoft.AspNet.Authentication": "1.0.0-*",
"Microsoft.AspNet.Authentication.OAuth": "1.0.0-*",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Moq": "4.2.1312.1622",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"commands": {
"test": "xunit.runner.aspnet"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Shouldly": "1.1.1.1"
}
}
}
}
来源:https://stackoverflow.com/questions/30556152/xunit-net-v2-not-discovering-net-core-tests-in-visual-studio-2015