How to test .NET Standard 2 library with either NUnit, xUnit or MSTest from either Rider or VS 2017?(如何使用 Rider 或 VS 2017 中的 NUnit、xUnit 或 MSTest 测试 .NET Standard 2 库?)
问题描述
我有一个使用 Azure Durable Functions 的项目,它们是仅在 .NET Standard 2 上可用.因此,它定义了可以在测试项目中使用的类库.但是,我无法将 xUnit、NUnit 或 MSTest 用于单元/集成测试的库放在一起.
I have a project where I use Azure Durable Functions, and they are available only on .NET Standard 2. So, it defines which class library can be used in testing projects. But, I cannot put together a library where either xUnit, NUnit or MSTest is used in unit/integration testing.
将 NUnit 添加到 .NET Standard 2 是类库的项目失败并出现以下错误:
Adding NUnit to a project where .NET Standard 2 is class library fails with the following error:
INFO:恢复包C:VSTSgithub.com etstandardXunitMsTestNunitsrcNetstandard2xUnitMsTestnUnit unit unit.csproj...调试:正在为 .NETStandard 恢复包,版本=v2.0... 调试:解决 .NETStandard,Version=v2.0 的冲突... 错误:循环检测到.nunit -> NUnit (>= 3.9.0).调试:检查兼容性.NETStandard 上的软件包,版本 = v2.0.调试:检查nunit 1.0.0 与 .NETStandard 的兼容性,Version=v2.0.
INFO: Restoring packages for C:VSTSgithub.com etstandardXunitMsTestNunitsrcNetstandard2xUnitMsTestnUnit unit unit.csproj... DEBUG: Restoring packages for .NETStandard,Version=v2.0... DEBUG: Resolving conflicts for .NETStandard,Version=v2.0... ERROR: Cycle detected. nunit -> NUnit (>= 3.9.0). DEBUG: Checking compatibility of packages on .NETStandard,Version=v2.0. DEBUG: Checking compatibility for nunit 1.0.0 with .NETStandard,Version=v2.0.
xUnit 的错误是一样的(只是错误消息谈到了 xUnit 循环).
The error is the same for xUnit (just the error message talks about xUnit cycle).
这两个错误也可以在 Rider 和 Visual Studio 2017 Enterprise 中重现.清理nuget缓存后我又试了一次.结果是一样的.
Both error can be reproduced in Rider and Visual Studio 2017 Enterprise too. I tried it again after I cleaned nuget cache. The result is the same.
如果是 MsTest,可以添加 ms 测试库,但测试发现对 Rider 和 Visual Studio 都不起作用.
In case of MsTest, possible to add ms test libraries, but test discovery does not work neither Rider and nor Visual Studio.
是否可以对 .NET Standard 2 库进行单元测试?
除了等待这些项目采用 .NET Standard 2 的内容外,我还能做些什么吗?
Is there anything I can do beside waiting for these projects to pick up .NET Standard 2 stuff?
我创建了一个小示例项目,可以在这里找到:https://github.com/SayusiAndo/netstandard2xunitresharper
I created a small sample project, can be found here: https://github.com/SayusiAndo/netstandard2xunitresharper
推荐答案
.NET Standard 没有运行时,所以它不会执行你的测试.
There is no runtime for .NET Standard, so it will not execute your tests.
您的测试程序集必须以可执行平台为目标,例如 .NET Framework 或 .NET Core 版本.
Your test assembly must target an executable platform, such as a version of .NET Framework or .NET Core.
<TargetFramework>net470</TargetFramework>
或者
<TargetFramework>netcoreapp2.0</TargetFramework>
有关详细信息,请参阅在不同框架上运行 .NET Standard 二进制文件.
See Running .NET Standard binaries on different frameworks for more details.
这篇关于如何使用 Rider 或 VS 2017 中的 NUnit、xUnit 或 MSTest 测试 .NET Standard 2 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Rider 或 VS 2017 中的 NUnit、xUnit 或 MSTest 测试 .NET Standard 2 库?


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01