Say you're building some class library with the intent to be used in multiple frameworks, like .Net Core and .Net (Full). Since NETStandard still hasn't really gotten off yet (and I think you should be waiting for 2.0 before you can use it as sole target), you may want to have your tests run for every supported framework.
With xUnit, that's actually quite easy! Just have your test projects project.json file target multiple frameworks like in the example below:
{ "dependencies": { "xunit": "2.2.0-beta2-build3300", "dotnet-test-xunit": "2.2.0-preview2-build1029", }, "testRunner": "xunit", "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" } } }, "net461": {} } }
Then run dotnet test and you'll see that both framework targets are being compiled and run:
dotnet test Compiling Dangl.Calculator for .NETStandard,Version=v1.4 ... Compiling Dangl.Calculator.Tests for .NETCoreApp,Version=v1.0 ... === TEST EXECUTION SUMMARY === Dangl.Calculator.Tests Total: 168, Errors: 0, Failed: 0, Skipped: 0, Time: 0,521s ... Compiling Dangl.Calculator.Tests for .NETFramework,Version=v4.6.1 ... === TEST EXECUTION SUMMARY === Dangl.Calculator.Tests Total: 168, Errors: 0, Failed: 0, Skipped: 0, Time: 0,324s SUMMARY: Total: 2 targets, Passed: 2, Failed: 0.
The dotnet test runner takes care of compiling the project both for .NETCoreApp,Version=v1.0 and .NETFramework,Version=v4.6.1 and runs the test suite for each. It also works with code coverage, so branches from conditional compilation are covered as well.
Happy Testing=)