Visual Studio 2015 RC1 Update 1 中的 XUnit 找不到测试
XUnit in Visual Studio 2015 RC1 Update 1 doesn't find tests
我在 Visual Studio 2015 年使用预览模板创建了一个 ASP.NET 5 项目。我通过 NuGet 安装了 XUnit,并在我的解决方案中添加了 "xUnit Test Project (DNX)"。
但是我的测试资源管理器什么也没显示,即使我在 Class1.cs 中有一个 public "Fact" 测试方法。当我"Run All Tests"时,"Tests"输出window为空。我的 "Build" 输出 window 显示 2 个项目构建成功。 (我的 ASP.NET 5 项目和我的 xUnit 项目。)
然而,当我构建或清理我的解决方案时,我在 "Tests" 输出中收到以下消息 window:
------ Discover test started ------
------ Test started: Project: MyProjectTest ------
Starting Microsoft.Dnx.TestHost [C:\Users\xxxxxx\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin\dnx.exe --appbase "C:\Users\xxxxxx\Documents\GitForWindows\Repositories\MySolution\MyProjectTest" Microsoft.Dnx.ApplicationHost --port 8424 Microsoft.Dnx.TestHost --port 8458 --parentProcessId 17312]
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Dnx.TestHost.Program.<>c__DisplayClass2_0.<<Main>b__0>d.MoveNext()
Unable to start Microsoft.Dnx.TestHost
========== Discover test finished: 0 found (0:00:01.057196) ==========
根据两个项目的属性window,我的解决方案 DNX SDK 版本是 1.0.0-rc1-update1。我还通过 dnvm 将其设置为 "active" 运行时,上述行为没有变化。不过,我不明白命令行中有关 运行 DNX 的说明,所以也许这是一个起点?
当我尝试将 DNX SDK 切换到 1.0.0-beta5 并清理解决方案时,我得到:
------ Discover test started ------
------ Test started: Project: MyProjectTest ------
Starting Microsoft.Framework.TestHost [C:\Users\xxxxx\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta5\bin\dnx.exe --appbase "C:\Users\xxxxxx\Documents\GitForWindows\Repositories\MySolution\MyProjectTest" Microsoft.Framework.ApplicationHost --port 9737 Microsoft.Framework.TestHost --port 9770 --parentProcessId 16732]
System.InvalidOperationException: Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
xunit 2.1.0
xunit.runner.dnx 2.1.0-beta6-build191
Searched Locations:
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\{name}\project.json
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\src\{name}\project.json
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\test\{name}\project.json
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\{name}.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_32\{name}\{version}\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_64\{name}\{version}\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\{name}\{version}\{name}.dll
Try running 'dnu restore'.
at Microsoft.Framework.Runtime.DefaultHost.GetEntryPoint(String applicationName)
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env)
at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args)
at dnx.host.RuntimeBootstrapper.Execute(String[] args)
Unable to start Microsoft.Framework.TestHost
========== Discover test finished: 0 found (0:00:01.4699978) ==========
运行 DNU 恢复没有解决任何问题。
编辑:这是要求的 project.json:
{
"version": "1.0.0-*",
"description": "",
"authors": [ "" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-beta6-build191"
},
"commands": {
"test": "xunit.runner.dnx"
},
"frameworks" : {
"dnx451": { },
"dnxcore50" : {
"dependencies": {
"System.Collections": "4.0.11-beta-23225",
"System.Linq": "4.0.1-beta-23225",
"System.Threading": "4.0.11-beta-23225",
"Microsoft.CSharp": "4.0.1-beta-23225"
}
}
}
}
您需要使用与 dnx 匹配的 xUnit 运行器版本。对于 dxn RC1,您需要使用 xunit.runner.dnx
的 2.1.0-rc1-build204 版本
我在 Visual Studio 2015 年使用预览模板创建了一个 ASP.NET 5 项目。我通过 NuGet 安装了 XUnit,并在我的解决方案中添加了 "xUnit Test Project (DNX)"。
但是我的测试资源管理器什么也没显示,即使我在 Class1.cs 中有一个 public "Fact" 测试方法。当我"Run All Tests"时,"Tests"输出window为空。我的 "Build" 输出 window 显示 2 个项目构建成功。 (我的 ASP.NET 5 项目和我的 xUnit 项目。)
然而,当我构建或清理我的解决方案时,我在 "Tests" 输出中收到以下消息 window:
------ Discover test started ------
------ Test started: Project: MyProjectTest ------
Starting Microsoft.Dnx.TestHost [C:\Users\xxxxxx\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin\dnx.exe --appbase "C:\Users\xxxxxx\Documents\GitForWindows\Repositories\MySolution\MyProjectTest" Microsoft.Dnx.ApplicationHost --port 8424 Microsoft.Dnx.TestHost --port 8458 --parentProcessId 17312]
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Dnx.TestHost.Program.<>c__DisplayClass2_0.<<Main>b__0>d.MoveNext()
Unable to start Microsoft.Dnx.TestHost
========== Discover test finished: 0 found (0:00:01.057196) ==========
根据两个项目的属性window,我的解决方案 DNX SDK 版本是 1.0.0-rc1-update1。我还通过 dnvm 将其设置为 "active" 运行时,上述行为没有变化。不过,我不明白命令行中有关 运行 DNX 的说明,所以也许这是一个起点?
当我尝试将 DNX SDK 切换到 1.0.0-beta5 并清理解决方案时,我得到:
------ Discover test started ------
------ Test started: Project: MyProjectTest ------
Starting Microsoft.Framework.TestHost [C:\Users\xxxxx\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta5\bin\dnx.exe --appbase "C:\Users\xxxxxx\Documents\GitForWindows\Repositories\MySolution\MyProjectTest" Microsoft.Framework.ApplicationHost --port 9737 Microsoft.Framework.TestHost --port 9770 --parentProcessId 16732]
System.InvalidOperationException: Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
xunit 2.1.0
xunit.runner.dnx 2.1.0-beta6-build191
Searched Locations:
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\{name}\project.json
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\src\{name}\project.json
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\test\{name}\project.json
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\{name}.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_32\{name}\{version}\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_64\{name}\{version}\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\{name}\{version}\{name}.dll
Try running 'dnu restore'.
at Microsoft.Framework.Runtime.DefaultHost.GetEntryPoint(String applicationName)
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env)
at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args)
at dnx.host.RuntimeBootstrapper.Execute(String[] args)
Unable to start Microsoft.Framework.TestHost
========== Discover test finished: 0 found (0:00:01.4699978) ==========
运行 DNU 恢复没有解决任何问题。
编辑:这是要求的 project.json:
{
"version": "1.0.0-*",
"description": "",
"authors": [ "" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-beta6-build191"
},
"commands": {
"test": "xunit.runner.dnx"
},
"frameworks" : {
"dnx451": { },
"dnxcore50" : {
"dependencies": {
"System.Collections": "4.0.11-beta-23225",
"System.Linq": "4.0.1-beta-23225",
"System.Threading": "4.0.11-beta-23225",
"Microsoft.CSharp": "4.0.1-beta-23225"
}
}
}
}
您需要使用与 dnx 匹配的 xUnit 运行器版本。对于 dxn RC1,您需要使用 xunit.runner.dnx
的 2.1.0-rc1-build204 版本