mercredi 13 juin 2018

Should a unit test project for a .NET Standard library target frameworks other than .NET Core?

When you have a .NET Standard library, the test project needs to target an actual platform. The most logical choice (I assume) is to target .NET Core because it runs on multiple operating systems, but it's also possible to target multiple platforms as demonstrated in the xUnit.net documentation:

With a single test project, we can have our tests run against multiple target frameworks. Open the .csproj file and change this:

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

To this:

<PropertyGroup>
  <TargetFrameworks>net452;netcoreapp2.1</TargetFrameworks>
</PropertyGroup>

Is there any practical reason for doing so, i.e. are there situations that require you to target multiple platforms?

The only reason I can think of is to be aware of bugs in a specific platform, which has occurred a couple times in .NET Framework. But that feels like you would be testing the platform instead of your library, so I'm not sure if that's a good enough reason.

Aucun commentaire:

Enregistrer un commentaire