如何使用 Rider 或 VS 2017 中的 NUnit、xUnit 或 MSTest 测试 .NET Standar

7

本文介绍了如何使用 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 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14