xunit.runner.visualstudio 不适用于 Visual Studio
Does xunit.runner.visualstudio not work for Visual Studio
我已经完成了这样的 nuget 安装:
Install-Package xunit.runner.visualstudio -Version 2.2.0
在我的测试项目上。
我有一个类似的测试:
public class When_Doing_Stuff_I_Want_To_Test
{
[Fact]
public void Can_Do_Stuff()
{
var result = DoStuff();
result.ShouldNotBeNull();
result.Success.ShouldBeTrue();
}
}
虽然我已经做了很多次 VS 重启,笔记本电脑重启,中间还有一天,但 VS 2017 仍然无法发现我的测试:
What can I do to fix this and see my tests?
附录
我在 4.6.1 下工作,所以还不是 Core。
关于同一主题的问题没有帮助:
- why-is-the-xunit-runner-not-finding-my-tests
- this response
- and this similar one
- xunit.runner.visualstudio not working on Visual Studio 2013 Update 4
所以有很多事情要做,none 其中有帮助...
更新
我也无法让 NUnit 工作,也不会出现在测试资源管理器中。
更新 2
我擦除我的项目并重新创建项目,如下所示:
然后我复制了我的原始代码并添加了所有必要的引用,没有区别。
在网上搜索后,似乎无法将目标 NETStandard.Library 用于测试项目...
这些是我从中获取信息的链接:
- Unit Tests not discovered in Visual Studio 2017
- Visual Studio 2017 RC does not detect nunit tests
- running xunit tests included in a .NET Standard 1.6 library
可以做的是让你想要测试的项目使用 NETStandard.Library 并让你的测试项目目标 Microsoft.NETCore.App。然后您的测试项目可以引用该项目进行测试,测试将 运行.
您的测试项目的 .csproj 看起来像这样(版本可能会更改):
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
要测试的项目是这样的:
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
最近我不得不 运行 dotnet restore 解决方案来获得 运行 的测试,所以你可以需要做同样的事情。 结果是 .NET Core SDK 1.0.1 而不是 1.0.4(我没有安装 x86 版本)。
转到菜单测试 -> 测试设置 -> 默认进程架构 -> 根据平台目标更改它。
我已经完成了这样的 nuget 安装:
Install-Package xunit.runner.visualstudio -Version 2.2.0
在我的测试项目上。
我有一个类似的测试:
public class When_Doing_Stuff_I_Want_To_Test
{
[Fact]
public void Can_Do_Stuff()
{
var result = DoStuff();
result.ShouldNotBeNull();
result.Success.ShouldBeTrue();
}
}
虽然我已经做了很多次 VS 重启,笔记本电脑重启,中间还有一天,但 VS 2017 仍然无法发现我的测试:
What can I do to fix this and see my tests?
附录
我在 4.6.1 下工作,所以还不是 Core。
关于同一主题的问题没有帮助:
- why-is-the-xunit-runner-not-finding-my-tests
- this response
- and this similar one
- xunit.runner.visualstudio not working on Visual Studio 2013 Update 4
所以有很多事情要做,none 其中有帮助...
更新
我也无法让 NUnit 工作,也不会出现在测试资源管理器中。
更新 2
我擦除我的项目并重新创建项目,如下所示:
然后我复制了我的原始代码并添加了所有必要的引用,没有区别。
在网上搜索后,似乎无法将目标 NETStandard.Library 用于测试项目...
这些是我从中获取信息的链接:
- Unit Tests not discovered in Visual Studio 2017
- Visual Studio 2017 RC does not detect nunit tests
- running xunit tests included in a .NET Standard 1.6 library
可以做的是让你想要测试的项目使用 NETStandard.Library 并让你的测试项目目标 Microsoft.NETCore.App。然后您的测试项目可以引用该项目进行测试,测试将 运行.
您的测试项目的 .csproj 看起来像这样(版本可能会更改):
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
要测试的项目是这样的:
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
最近我不得不 运行 dotnet restore 解决方案来获得 运行 的测试,所以你可以需要做同样的事情。 结果是 .NET Core SDK 1.0.1 而不是 1.0.4(我没有安装 x86 版本)。
转到菜单测试 -> 测试设置 -> 默认进程架构 -> 根据平台目标更改它。