'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> <TargetFramework>net452;netcoreapp2.1</TargetFramework> </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.
Solution 1:[1]
If you create a NETStandard library, you should consider running the tests on every target platform and runtime version that you expect to see usage on.
If you plan to publish your library, you can't be sure about who is going to reference it in which scenario.
Not only are there differences between target platforms, there are also changing implementation details from one version to another of the same platform (see this example).
This isn't so much testing the platform rather it's testing if your library plays nicely with the platform.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MikeLimaSierra |
