Training
Module
C# testing in Visual Studio - Training
Start testing your C# apps by using the testing tools in Visual Studio. Learn to write tests, use Test Explorer, create test suites, and apply the red, green, refactor pattern to write code.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When you create a test project in Microsoft Visual Studio, the most recent version of the .NET Framework is set as the target, by default. Additionally, if you upgrade test projects from previous versions of Visual Studio, they are upgraded to target the most recent version of the .NET Framework. By editing the project properties, you can explicitly re-target the project to earlier versions of the .NET Framework.
You can create unit test projects that target specific versions of the .NET Framework. The targeted version must be 3.5 or later, and cannot be a client version. Visual Studio enables the following basic support for unit tests that target specific versions:
You can create unit test projects and target them to a specific version of the .NET Framework.
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.
Testing SharePoint Applications
The capabilities listed above also enable you to write unit tests and integration tests for SharePoint applications using Visual Studio. For more information about how to develop SharePoint applications using Visual Studio, see Create SharePoint solutions, Build and debug SharePoint solutions and Verify and debug SharePoint code.
Limitations
The following limitations apply when you re-target your test projects to use earlier versions of the .NET Framework:
In the .NET Framework 3.5, multitargeting is supported for test projects that contain only unit tests. The .NET Framework 3.5 does not support any other test type, such as coded UI or load test. The re-targeting is blocked for test types other than unit tests.
Execution of tests that are targeted at an earlier version of the .NET Framework is supported only in the default host adapter. It is not supported in the ASP.NET host adapter. ASP.NET applications that have to run in the ASP.NET Development Server context must be compatible with the current version of the .NET Framework.
Data collection support is disabled when you run tests that support .NET Framework 3.5 multitargeting. You can run code coverage by using the Visual Studio command-line tools.
Unit tests that use .NET Framework 3.5 cannot run on a remote machine.
You cannot target unit tests to earlier client versions of the framework.
Create a new Visual Basic Unit Test Project project.
In Solution Explorer, choose Properties from the right-click menu of the new Visual Basic test project.
The properties for your Visual Basic test project are displayed.
On the Compile tab, choose Advanced Compile Options as shown in the following illustration.
Use the Target framework (all configurations) drop-down list to change the target framework to .NET Framework 3.5 or a later version as shown in callout B in the following illustration. You should not specify a client version.
Create a new C# Unit Test Project project.
In Solution Explorer, choose Properties from the right-click menu of your new C# test project.
The properties for your C# test project are displayed.
On the Application tab, choose Target framework. From the drop-down list, choose .NET Framework 3.5 or a later version, as shown in the following illustration. You should not specify a client version.
Create a new C++ Unit Test Project project.
Warning
To build C++/CLI unit tests for a previous version of the .NET Framework for Visual C++, you must use the corresponding version of Visual Studio.
In Solution Explorer, choose Unload Project from your new C++ test project.
In Solution Explorer, choose the unloaded C++ test project and then choose Edit <project name>.vcxproj.
The .vcxproj file opens in the editor.
Set the TargetFrameworkVersion
to version 3.5 or a later version in the PropertyGroup
labeled "Globals"
. You should not specify a client version:
<PropertyGroup Label="Globals">
<TargetName>DefaultTest</TargetName>
<ProjectTypes>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}</ProjectTypes>
<ProjectGUID>{CE16D77A-E364-4ACD-948B-1EB6218B0EA3}</ProjectGUID>
<TargetFrameworkVersion>3.5</TargetFrameworkVersion>
<Keyword>ManagedCProj</Keyword>
<RootNamespace>CPP_Test</RootNamespace>
</PropertyGroup>
Save and close the .vcxproj file.
In Solution Explorer, choose select Reload Project from the right-click menu of your new C++ test project.
Training
Module
C# testing in Visual Studio - Training
Start testing your C# apps by using the testing tools in Visual Studio. Learn to write tests, use Test Explorer, create test suites, and apply the red, green, refactor pattern to write code.
Documentation
Update from MSTestV1 to MSTestV2 - Visual Studio (Windows)
Upgrade an MSTestV1 test project to target MSTestV2 in the .csproj file, and review the MSTestV1 features that aren't available in MSTestV2.
Unit testing C# with MSTest and .NET - .NET
Learn unit test concepts in C# and .NET through an interactive experience building a sample solution step-by-step using dotnet test and MSTest.
Create Data-Driven Unit Tests - Visual Studio (Windows)
Learn how to use the Microsoft unit test framework for managed code to set up a unit test method to retrieve values from a data source.
Create, run, and customize C# unit tests - Visual Studio (Windows)
Learn how to create, run, and customize a series of unit tests using the Microsoft unit test framework for managed code and Visual Studio Test Explorer.