如何使用Rider或VS 2017中的NUnit,xUnit或MSTest测试.NET Standard 2库? [英] How to test .NET Standard 2 library with either NUnit, xUnit or MSTest from either Rider or VS 2017?

查看:553
本文介绍了如何使用Rider或VS 2017中的NUnit,xUnit或MSTest测试.NET Standard 2库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中使用 Azure持久功能,它们是仅在.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:\VSTS\github.com\ netstandardXunitMsTestNunit\src\Netstandard2xUnitMsTestnUnit\nunit\nunit.csproj ...
调试:恢复.NETStandard的软件包,版本= v2.0 ...调试:
解决.NETStandard的冲突,版本= v2.0 ...错误:检测到循环
。 nunit-> NUnit(> = 3.9.0)。调试:检查.NETStandard,Version = v2.0上软件包的兼容性
。调试:使用.NETStandard,Version = v2.0检查nunit 1.0.0的
兼容性。

INFO: Restoring packages for C:\VSTS\github.com\netstandardXunitMsTestNunit\src\Netstandard2xUnitMsTestnUnit\nunit\nunit.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


推荐答案

.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 Binaries在不同框架上以获取更多详细信息。

See Running .NET Standard binaries on different frameworks for more details.

这篇关于如何使用Rider或VS 2017中的NUnit,xUnit或MSTest测试.NET Standard 2库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆