How do you run unit tests for a specific target framework in Visual Studio 2017/2019?

mstest
visual studio 2017 run unit tests from command line
microsoft unit testing framework for c++
nunit
xunit
how to run unit test in visual studio 2017
visual studio 2019 tests not running
arrange, act, assert

I am really loving the new .csproj format. It is so much better than that dreaded (limited) project.json.

However, there is one thing that I am trying to work out. I have merged my (multiple) test projects into a single multi-targeted project.

<TargetFrameworks>netcoreapp1.0;net40;net35</TargetFrameworks>

But, there doesn't seem to be any tooling in Test Explorer in Visual Studio to select the target framework - it always just runs the first one. I found a workaround - to add a <TargetFramework> element with a specific framework...

<TargetFramework>net35</TargetFramework>

But, is there any way to select the target framework without resorting to hand-editing the MSBuild (.csproj) file? I am looking for some option in the GUI to do this - specifically so I don't have to remember to edit the .csproj file in order to switch frameworks before debugging a test or to remember to have to remove this line before the release.


I know that the question is about VS, but I find useful that when targeting multiple frameworks dotnet tests command will run tests for all frameworks in <TargetFrameworks> node:

> dotnet test
...
Test run for [projectPath]\bin\Debug\netcoreapp1.1\XUnitTestProject.dll(.NETCoreApp,Version=v1.1)
...
Test run for [projectPath]\bin\Debug\net461\XUnitTestProject.dll(.NETFramework,Version=v4.6.1)
...

NCrunch can also recognize multiple targets and run tests for every target automatically:

Unit Tests Target Earlier Version of .NET Framework, NET Framework from Visual Studio on your local machine. You can run unit tests that target a specific version of the .NET Framework by using  You can run unit tests that target a specific version of the.NET Framework from Visual Studio on your local machine. You can run unit tests that target a specific version of the.NET Framework by using MSTest.exe from the command prompt. You can run unit tests on a build agent as part of a build.


Use TargetFrameWorkVersion in a runsettings file using the 'or' operator.

Run and debug unit tests with Test Explorer, Learn how to run tests with Test Explorer in Visual Studio. This topic Visual Studio includes the Microsoft unit testing frameworks for both managed and native code. However NET, regardless of the language of the target code. To filter to specific traits, click the filter icon at the top of the Traits column. You can run unit tests in Visual Studio by using third-party test frameworks such as Boost, Google, and NUnit. Use the NuGet Package Manager to install the NuGet package for the framework of your choice.


Best option currently is to change the order of your target frameworks in the csproj.

<PropertyGroup>
    <TargetFrameworks>netcoreapp2.1;net45;net46;net461;net462;net47</TargetFrameworks>
</PropertyGroup>

If wanting to debug unit tests for net45 framework, you'll need to change it to:

<PropertyGroup>
    <TargetFrameworks>net45;net46;net461;net462;net47;netcoreapp2.1</TargetFrameworks>
</PropertyGroup>

The UI for doing this in Visual Studio would be relatively simple to implement but they have not done so as of this answer.

Getting Started: .NET Framework with Visual Studio > xUnit.net, How do you run unit tests for a specific target framework in Visual Studio 2017/​2019? mstest visual studio 2017 run unit tests from command line microsoft unit  Run tests in Test Explorer When you build the test project, the tests appear in Test Explorer. If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer. As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.


It turns out that Microsoft has finally fixed this in Visual Studio 2019 (not sure exactly when).

If you specify multiple target frameworks:

<TargetFrameworks>netcoreapp2.1;net451</TargetFrameworks>

The GUI now displays:

and lets you run tests on all target platforms at once.

Multi-Targeting and Porting a .NET Library to .NET Core 2.0, Note: The examples were done with xUnit.net v2.2 and Visual Studio 2017. In particular, it brings packages that include the core unit testing framework and the assertion id="xunit.assert" version="2.2.0" targetFramework="net452" /> <​package We will use one of these tools—the console runner—to run your unit tests. Visual Studio supports two testing frameworks for Python, unittest and pytest (available in Visual Studio 2019 starting with version 16.3). By default, no framework is selected when you create a Python project. To specify a framework, right-click on the project name in Solution Explorer and select the Properties option.


Running tests in a csproj with multiple TargetFrameworks · Issue , NET Standard 2.0 in the release version of Visual Studio, and that's why the It's relatively easy to set target specific build and configuration options. NET 4.5 constants applied and run unit tests with that framework use: xml. To get started, select a method, a type, or a namespace in the code editor in the project you want to test, right-click, and then choose Create Unit Tests. The Create Unit Tests dialog opens where you can configure how you want the tests to be created. Set unit test traits


ReSharper, .NET Core and unit testing, As of Visual Studio 2019 Version 16.2 the test explorer can display and run multi-​targeted tests. For more info on using the target framework  For example, if statements, assertions, and all operations that can throw exceptions are analyzed. This analysis is used to generate test data for a parameterized unit test for each of your methods, creating unit tests with high code coverage. When you run IntelliTest, you can easily see which tests are failing and add any necessary code to fix


NUnit testing using the new project format, The first thing we need to do is get our project set up for unit testing. a lot easier to run a specific test for a specific target framework, straight from NET Core 1.0 and 1.1 projects in both Visual Studio 2015 and Visual Studio  After enabling a test framework, use the Python: Discover Tests command to scan the project for tests according to the discovery patterns of the currently selected test framework. Once discovered, Visual Studio Code provides a variety of means to run tests and debug tests.