Support Multiple frameworks UT

Support Multiple frameworks UT

Background
we have a Project name Plan Visualization, It is a plugin project , This project have 2 framework to support different platform, .net framework 4.6.1 for desktop , .net core 2.2 for Azure Web service. both of them sharing some common library. the common library framework is .net standard 2.0. we need do Unit testing for the common library , because .net standard no run time library, so we cannot create a Unit testing project with .net standard framework. so we need use Multiple frameworks.

NET Standard is a specification that each .NET Standard version(such as .NET Framework, .NET Core and Xamarin) defines the set of APIs that all .NET implementations must provide to conform to that version. You library has a value for TargetFramework of netstandard2.0 means you can reference the logic library not only from a .NET Core app, but also from an app built for .NET Framework or Xamarin.

So if you want to test the library, you need to specify the targets of which your library would support. And if you want to support multiple .NET version then you should test them all to make sure your library can run on these targets correctly. Here’s the configuration of target framework in .csproj:

Single target:

net461
Multiple targets:
netcoreapp2.0;net461

How to do

  1. Create a SDK Style Project:
  1. Set multiple frameworks in csproj file
    open project file, change to , add the frameworks you want to support.

    here is the framework list:https://docs.microsoft.com/en-us/dotnet/standard/frameworks

  2. Reference Test SDK to project

    Microsoft.NET.Test.Sdk
    NUnit3TestAdapter
    NunitXml.TestLogger

  3. Run UT in Commaindline
    run all framework test:  dotnet test
    run specific framework test: dotnet test -f netcoreapp2.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值