Microsoft.VisualStudio.Sdk.TestFramework 17.11.8

Prefix Reserved
dotnet add package Microsoft.VisualStudio.Sdk.TestFramework --version 17.11.8                
NuGet\Install-Package Microsoft.VisualStudio.Sdk.TestFramework -Version 17.11.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.11.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microsoft.VisualStudio.Sdk.TestFramework --version 17.11.8                
#r "nuget: Microsoft.VisualStudio.Sdk.TestFramework, 17.11.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Microsoft.VisualStudio.Sdk.TestFramework as a Cake Addin
#addin nuget:?package=Microsoft.VisualStudio.Sdk.TestFramework&version=17.11.8

// Install Microsoft.VisualStudio.Sdk.TestFramework as a Cake Tool
#tool nuget:?package=Microsoft.VisualStudio.Sdk.TestFramework&version=17.11.8                

Microsoft.VisualStudio.Sdk.TestFramework

The VS SDK Test Framework is a library for your unit tests that exercise VS code to use so that certain core VS functionality works outside the VS process so your unit tests can function. For example, ThreadHelper and obtaining global services from the static ServiceProvider tend to fail in unit tests without this library installed.

Consuming this test framework

Microsoft Internal users: See specific guidance if consuming within the VS repo.

  1. Install the NuGet package Microsoft.VisualStudio.Sdk.TestFramework, or for Xunit test projects, install the more specific Microsoft.VisualStudio.Sdk.TestFramework.Xunit package

  2. Make sure your unit test project generates the required binding redirects by adding these two properties to your project file:

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    
  3. Apply some changes to your test project source as appropriate given the test framework you're already using:

Main Thread considerations

This library will create a mocked up UI thread, such that ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync() can switch to it. Your unit tests do not start on this mocked up UI thread. If your product code contains checks that it is invoked on the UI thread (e.g. ThreadHelper.ThrowIfNotOnUIThread()) your test method should look like this:

[TestMethod] // or [Fact]
public async Task VerifyWeDoSomethingGood()
{
    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
    MyVSPackage.DoSomethingAwesome();
}

Built in service mocks

There are a collection of "base services" that the VSSDKTestFx comes with mocks for. Calling GlobalServiceProvider.AddService for any of these will result in an InvalidOperationException being thrown claiming that the service is already added.

These services include:

  • SVsActivityLog Customize behavior by acquiring the service and downcasting to the MockVsActivityLog type, then setting the ForwardTo property.
  • OLE.Interop.IServiceProvider
  • SVsTaskSchedulerService
  • SVsUIThreadInvokerPrivate

More may be added and can be found in source code.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net8.0-windows8.0 is compatible. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Microsoft.VisualStudio.Sdk.TestFramework:

Package Downloads
Microsoft.VisualStudio.Sdk.TestFramework.Xunit

A test library to help in writing unit and integration tests for Visual Studio extensions.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Microsoft.VisualStudio.Sdk.TestFramework:

Repository Stars
rubicon-oss/LicenseHeaderManager
Manage license headers for your source code files in Visual Studio
Version Downloads Last updated
17.11.8 167 10/26/2024
17.6.16 69,519 7/10/2023
17.2.7 21,437 6/21/2022
17.2.5 786 5/25/2022
17.1.3-alpha 299 1/13/2022
17.0.15 4,915 11/19/2021
16.5.22-beta 7,925 10/27/2020