简体   繁体   中英

Framework/visual studio project type to use for unit testing .net standard libray?

Given that the implementation of the .net standard library is provided by the underlined implementation ( .Net framework , .Net Core (windows/Linux etc) ). And it is possible that the APIs have little different behaviour. TimeZoneInfo.Id provides different results based on the OS (last time I checked).

So, how to unit test? In visual studio we can either create a .Net Core xUnit project or .Net Framework xUnit project. How to run the same xUnit tests in two different environment?

The simplest way is to multi-target the test project. That is, create a .NET Core xUnit project from the template and change

<TargetFramework>netcoreapp1.1</TargetFramework>

to

<TargetFrameworks>netcoreapp1.1;net461</TargetFrameworks>

Note the change to plural / additional s here. The plural form allows you to specify multiple target frameworks to test on, so you could easily add multiple versions of .NET Core and .NET Standard.

While the VS-integrated test runner will only run the first framework at the moment (see this tracking issue on GitHub ), dotnet test on the console will run your tests on all specified configurations.

Instead of targeting multiple runtimes, you could just as well use a test platform that is capable of running net standard tests by default. Nuclear.Test can help you with a more complete feature test of your implementation on multiple platforms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM